我尝试在我的应用上实现一个简单的Map,但在使用下面的React Leaflet示例代码时遇到此错误。
import React from "react";
import { MapContainer, TileLayer, Marker, Popup } from "react-leaflet";
export default function App() {
return (
<MapContainer center={[51.505, -0.09]} zoom={13} scrollWheelZoom={false}>
<TileLayer
attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
<Marker position={[51.505, -0.09]}>
<Popup>
A pretty CSS3 popup. <br /> Easily customizable.
</Popup>
</Marker>
</MapContainer>
);
}
错误:
Type '{ children: Element[]; center: number[]; zoom: number; scrollWheelZoom: boolean; }' is not assignable to type 'IntrinsicAttributes & MapContainerProps'.
Property 'center' does not exist on type 'IntrinsicAttributes & MapContainerProps'. TS2322
150 | />
151 |
> 152 | <MapContainer center={[51.505, -0.09]} zoom={13} scrollWheelZoom={false}>
| ^
153 | <TileLayer
154 | attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
155 | url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
我用的是React和Typescript。
1条答案
按热度按时间ohfgkhjo1#
尝试安装传单类型:
然后重新启动项目。