zoukankan      html  css  js  c++  java
  • vue setTimeout 和 this.$nextTick,BMap api

    <el-col :span="24" >
                	<div style="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);
          
        })
      }
    

      

  • 相关阅读:
    mysql高并发配置
    php xml转array的方法
    双系统,一系统损坏后的解决方案之硬盘启动
    最长公共前缀
    罗马数字转整数
    回文数
    整数反转
    一、数组---两数之和
    从尾到头打印链表
    替换空格
  • 原文地址:https://www.cnblogs.com/yyzyou/p/12196839.html
Copyright © 2011-2022 走看看