高德地图script标签引入到vue
<template>
<div id="subwayContent" style="width:100%;height:100%"></div>
</template>
<script>
export default {
data() {
return {
}
},
components: {},
created() {
},
mounted() {
const oScript = document.createElement('script');
oScript.type = 'text/javascript';
oScript.src = '//webapi.amap.com/maps?v=1.4.15&key=自己的key';
document.body.appendChild(oScript);
this.init()
},
methods: {
init() {
var test2 = setInterval(() => {
console.log(111)
try {
this.map = new AMap.Map('subwayContent', {
resizeEnable: true,
rotateEnable: true,
pitchEnable: true,
showLabel: true,
zoom: 11,
pitch: 60,
rotation: -15,
viewMode: '3D',
cursor: 'hand',
expandZoomRange: true,
zooms: [3, 20],
skyColor: '#132237',
})
clearInterval(test2)
} catch (error) {
console.log(error)
}
}, 10)
}
}
}
</script>
<style lang="scss" scoped>
</style>
|