1.创建bmap.js
import "echarts/extension/bmap/bmap.js";
export function MP(ak) {
return new Promise(function (resolve, reject) {
window.onload = function () {
resolve(BMap)
}
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://api.map.baidu.com/api?v=3.0&ak=" + ak + "&callback=init";
script.onerror = reject;
document.head.appendChild(script);
})
}
2.页面中
import { MP } from "@/bmap.js";
mounted() {
this.$nextTick(() => {
let _this = this;
MP("ouRIeiXUwefUtUxhMC5DDWHFL4WgU8tU").then((BMap) => {
_this.$refs.busMap.style.height =
window.screen.availHeight * 0.9 + "px";
_this.$nextTick(() => {
_this.draw(BMap);
});
});
});
|