3 回答

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超6個(gè)贊
僅供參考,Promise無(wú)法使用涉及回調(diào)的循環(huán),即forEach。或者,您可以使用for of
try {
for (const val of response.data['users']) {
console.log("ENTER");
var url = 'getDetailUser' + val["id"];
var res = await call(url);
console.log("EXIT")
}
} catch (error) {
console.log(error)
}

TA貢獻(xiàn)1982條經(jīng)驗(yàn) 獲得超2個(gè)贊
只需稍作改動(dòng)
await Promise.allSettled(response.data["users"].map(val => {
? ?var url = 'getDetailUser' + val["id"];
? ?return call(url);?
}))

TA貢獻(xiàn)1773條經(jīng)驗(yàn) 獲得超3個(gè)贊
Promise.all() 就是這樣
await Promise.all(response.data["users"].map(val => {
var url = 'getDetailUser' + val["id"];
return call(url);
}))
添加回答
舉報(bào)