我測試下來目前懷疑是javascript 異步執(zhí)行的原因 。懷疑就是axios 還沒執(zhí)行完,賦值就已經(jīng)發(fā)生了。我先自己測試嘗試解決。1.我用VUE的 easytable 想加個(gè) footer 的數(shù)據(jù)匯總,不知道怎樣可以獲取到table 數(shù)據(jù)。 easytable 說明: http://doc.huangsw.com/vue-ea...2.代碼: tableData: 是VUE,data中定義的一個(gè)空數(shù)組。 .下面這個(gè)函數(shù)是定義在VUE,Methods,用來求和計(jì)算的:setFooterData () {axios.get('/asset/hosts').then(res => { this.tableData = res.data })console.log('========\n', this.tableData)let Cost111 = this.tableData.map(item => {return item.CostByMonth})...(后面的省去)}3.問題: 我沒有想明白的問題是:為什么axios.get() 之后那一句 console.log 打印出來的 this.tableData 是空的數(shù)組。 導(dǎo)致我后面Cost111 獲取不到數(shù)據(jù)。axios.get函數(shù)里面的 this.tableData 數(shù)據(jù)實(shí)際是獲取到的。只是setFooterData() 這個(gè)函數(shù)里面我不知道如何獲取保存這個(gè)axios得到的響應(yīng)數(shù)據(jù)tableData。4.不知道講問題明白了沒,小弟愚笨,非程序員出身,都是自學(xué)搗鼓的,也沒有人可以交流,路走的很苦,希望有人指點(diǎn)一二。
vue easytable axios 數(shù)據(jù)賦值問題
慕運(yùn)維8079593
2019-03-29 16:19:31