我該如何解決這個錯誤?我該如何解決「Uncaught TypeError:無法讀取未定義的屬性'map'?
SimpleMap.js:35, Uncaught TypeError: Cannot read property 'map' of undefined
import React from "react";
import {GoogleMapLoader, GoogleMap, Marker} from "react-google- maps";
export default function SimpleMap (props) {
var markers = [{
position:
{ lat: -34.397, lng: 150.644 }
,
index: "1"
}];
return (
<section style={{height: "100%"}}>
<GoogleMapLoader
query={{ libraries: "geometry,drawing,places,visualization" }}
containerElement={
<div
{...props.containerElementProps}
style={{
height: "100%",
}}
/>
}
googleMapElement={
<GoogleMap
ref={(map) => console.log(map)}
defaultZoom={3}
defaultCenter={{ lat: -25.363882, lng: 131.044922 }}
onClick={props.onMapClick}
>
{props.markers.map((marker) => {
return (
<Marker
{...marker}
onRightclick={() => props.onMarkerRightclick(index)} />
);
})}
</GoogleMap>
}
></GoogleMapLoader>
</section>
);
}
'props.markers'在第35行未定義。 –
將第6行從'var markers ='更改爲'props.markers ='並查看是否有幫助。 –
它給出了這個錯誤。 SimpleMap.js:6 Uncaught TypeError:不能添加屬性標記,對象不可擴展。 –