因为项目中其他文件都是公共文件,不能再index.html中使用script标签全局引入,在自己的的页面引入,使用的uniapp 所以在onReady中
const script = document.createElement('script');
script.src = 'https://map.sgcc.com.cn/maps?v=3.0.0';
document.head.appendChild(script);
script.onload = () => {
// 在地图脚本加载完成后,你可以在这里使用地图相关的功能
this.$nextTick(() => {
console.log("1111111");
SGMap.tokenTask
.login(
"地图token",
"地图key"
)
.then(function() {
that.initMap([116.397428, 39.90923]);
that.loadPlugin();
});
});
};
这里要注意一的是需要等待script标签生成后在执行初始化地图等功能直接使用script标签引入的话会失效,所以这里面使用onload监听完成后在执行初始化操作