代码如下:
methods: {
createMap (BMap) {
let map = new BMap.Map('allmap')
let point = new BMap.Point(120.127401, 30.288469)
map.centerAndZoom(point, 18) // 初始化地图,设置中心点坐标和地图级别
var myGeo = new BMap.Geocoder()
// 将地址解析结果显示在地图上,并调整地图视野
myGeo.getPoint('杭州市西湖区文二路391号', function (point) {
if (point) {
map.centerAndZoom(point, 18)
} else {
console.log('您选择地址没有解析到结果!')
}
}, '杭州市')
}
},
mounted () {
let that = this
window.BMap_loadScriptTime = (new Date()).getTime()
const oScript = document.createElement('script')
oScript.src = 'http://api.map.baidu.com/getscript?v=2.0&ak=PNhhMFEMvIgiZ8LO09zFNeBd3pHtnM7r&services=&t=20170511202040'
oScript.type = 'text/javascript'
document.head.appendChild(oScript)
window.onload = function () {
that.$nextTick(
that.createMap(this.BMap)
)
}
}
将window.onload改成oScript.onload