我在 JavaScript 中创建了一些函数。
我发现我在许多项目中重复使用它们。
所以我决定为我的编码创建一个小的 JavaScript 库。像 react、react-dom、jquery 这样的库,我可以用 npm 安装它:
npm install <my-personal-library>
我在网上搜了一下。我了解到我可以使用npm publish <my-personal-library,但我不知道如何格式化我的库和函数,以便像 npm 包一样使用和安装它们。
我也不知道为我的函数和库创建类型定义。像@types/react 任何指导?
我想在我的 React-Leaflet 地图上创建一张卡片,显示地图的一些详细信息。但我的第一个问题是,我不能将我的 div(卡片容器)过度覆盖在地图顶部。这是我的代码:
class SimpleExample extends React.Component {
constructor() {
super()
this.state = {
lat: 51.505,
lng: -0.09,
zoom: 13
}
}
render() {
const position = [this.state.lat, this.state.lng];
return (
<LeafletMap center={position} zoom={this.state.zoom}
id='mapDiv'
>
<div
style={{
width: 500,
height: 500,
top: 0,
left: 0,
backgroundColor: 'red',
zIndex: 10
}}
/>
<TileLayer
attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
url='https://{s}.tile.osm.org/{z}/{x}/{y}.png'
/>
<Marker position={position}>
<Popup>
A pretty CSS3 popup. <br/> Easily customizable.
</Popup>
</Marker>
</LeafletMap>
);
}
}
ReactDOM.render(<SimpleExample />, document.getElementById('container'))```
Run Code Online (Sandbox Code Playgroud)