有的项目需要引入地图,不想开始加载的时候再引用
created () {
// console.log('created1111')
if (!window.AMap) {
// 引用地图script标签
const oScript = document.createElement('script')
oScript.type = 'text/javascript'
oScript.src = 'https://webapi.amap.com/maps?v=1.4.15&key=您申请的key'
try {
document.body.appendChild(oScript)
} catch (error) { }
}
},
mounted () {
// console.log(AMap)
if (window.AMap) {
this.initGisMap()
}
else {
setTimeout(() => {
this.initGisMap()
}, 3000)
}
},
methods: {
initGisMap () {
this.gdMap = new AMap.Map("map", {
resizeEnable: true,
viewMode: "3D",
pitch: 50,
rotation: 0,
expandZoomRange: true,
center: [121.380857, 31.112834],
zooms: [3, 30],
zoom: 13,
buildingAnimation: true,
});
}
},