vue setTimeout 和 this.$nextTick,BMap api

1
2
3
<el-col :span="24" >
                <div style="width:100%;height:300px;" id="allmap"></div>
        </el-col>

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
        import {MP} from '../../../util/baiDuMap'
 
 
setTimeout在vue里需生命变量this, 参数是函数
    let _this=this
    setTimeout( function()  { _this.path=arr;  _this.play = true;},idx*10)
 
  mounted() {
  this.$nextTick(function(){
       MP().then(BMap => {
        //在此调用api
    var map = new BMap.Map("allmap");    // 创建Map实例
    map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);  // 初始化地图,设置中心点坐标和地图级别
     
    map.setCurrentCity("北京");          // 设置地图显示的城市 此项是必须设置的
    map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
 
       });
       })
}

  

1
baiDuMap.js文件
1
2
3
4
5
6
7
8
9
10
11
12
13
export function MP() {
    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=2.0&ak=TI7gCHQoTkipcLw50VvOSYYP&callback=init";
      script.onerror = reject;
      document.head.appendChild(script);
       
    })
  }

  

posted @   yufeiyunsui  阅读(1000)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示