鍍金池/ 問答/HTML5  Linux  HTML/ vue data 問題

vue data 問題

圖片描述

為什么這樣子打印不到數(shù)據(jù)呢??

回答
編輯回答
兔寶寶

為什么不把log寫在請求里面

2017年5月17日 12:11
編輯回答
夢囈

因為getDate是異步請求,drawMap執(zhí)行的時候,數(shù)據(jù)請求還沒有完成,所以打印不到,你可以把drawMap當作getDate的回調(diào)去執(zhí)行

this.getDate(this.drawMap)

//this.getDate
getDate(callback){
    ....then(res=>{
        callback && callback()
        //this.drawMap()
    })
}

也可以在getDate中把Promise對象return出去

this.getDate().then(res=>{this.drawMap()})
2017年8月3日 22:33
編輯回答
孤慣

因為數(shù)據(jù)都被代理了

2018年2月15日 03:23
編輯回答
離人歸

異步請求,老鐵

2018年3月11日 10:47
編輯回答
嘟尛嘴

第一個 是異步函數(shù), 第二個是同步。 我看著想
例如
var a
setTimeout(() => {a = 2}, 200)
setTimeout(() => {console.log('aa',a)}, 1000)
!(function () {
console.log('a',a)
})()

2017年7月3日 16:39
編輯回答
真難過

老鐵,你這問題問題有點尷尬

2018年6月25日 18:06
編輯回答
尤禮

頗為尷尬,畢竟新手

2017年7月9日 13:49