vue setTimeout 和 this.$nextTick,BMap api


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

  

        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);     //開啟鼠標滾輪縮放

       });
       })
}

  

baiDuMap.js文件
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);
      
    })
  }

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM