js promise 同步異步數據展示問題?

js promise 同步異步數據展示問題?

getIanMediumList().then(res => {

this.mixItems = this.mixItems.concat(res.items)

console.log('A': this.mixItems)

})

getGreenMediumList().then(res => {

this.mixItems = this.mixItems.concat(res.items)

console.log('B': this.mixItems)

})

console.log('C': this.mixItems)

A跟B都可以展示出數據
但是C展示不出來,會是空的
如何等兩個都完成後,讓C取得數據?


回答:

有异步了当然就得继续异步……

let p1 = getIanMediumList().then(res => {

this.mixItems = this.mixItems.concat(res.items)

console.log('A': this.mixItems)

})

let p2 = getGreenMediumList().then(res => {

this.mixItems = this.mixItems.concat(res.items)

console.log('B': this.mixItems)

})

Promise.all([p1, p2]).then(() => {

console.log('C': this.mixItems)

})

以上是 js promise 同步異步數據展示問題? 的全部内容, 来源链接: utcz.com/p/935904.html

回到顶部