vue项目中,高德地图使用。
引入vue中。异步导入vue中。
gaoDe(key) {
window.onApiLoaded = function () {
var map = new AMap.Map(‘container‘, {
resizeEnable: true,
center: [113.951955, 22.530825],
zoom: 16
});
}
var url = `https://webapi.amap.com/maps? v=1.4.15&key=${key}&callback=onApiLoaded`;
var jsapi = document.createElement(‘script‘);
jsapi.charset = ‘utf-8‘;
jsapi.src = url;
document.head.appendChild(jsapi);
mounted() {
this.gaoDe(‘key‘);
},
在vue组件中使用,直接写在mouted中会出现AMap未定义的报错!
目前,个人是使用定时器解决的。
// 地图接口API
mapCom() {
let _this = this;
window.onLoad = function () {
var map = new AMap.Map(‘mapBox‘, {
resizeEna