1.创建一个div
<div id="map"></div>
2.设置div样式
3.在data中使用map
data () {
return {
map:''
}
}
4.在mounted中初始化地图
init1() {
this.map = L.map("map", {
center: [31.6, 108.5],
zoom: 5,
maxZoom: 20,
minZoom: 3,
zoomControl: false,
attributionControl: false,
});
//添加想要展示的地图模板
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© OpenStreetMap'
}).addTo(map);
}
!!vue要在main.js里要引入leaflet样式