4 回答
动漫人物
TA贡献1815条经验 获得超10个赞
因为getDate是异步请求,drawMap执行的时候,数据请求还没有完成,所以打印不到,你可以把drawMap当作getDate的回调去执行
this.getDate(this.drawMap)
//this.getDate
getDate(callback){
....then(res=>{
callback && callback()
//this.drawMap()
})
}
也可以在getDate中把Promise对象return出去
this.getDate().then(res=>{this.drawMap()})
慕妹3242003
TA贡献1824条经验 获得超6个赞
第一个 是异步函数, 第二个是同步。 我看着想
例如
var a
setTimeout(() => {a = 2}, 200)
setTimeout(() => {console.log('aa',a)}, 1000)
!(function () {
console.log('a',a)
})()
添加回答
举报
0/150
提交
取消
