const tList = ['id:123', 'id:46', 'id:83'];
const resObj = {};
const state = [];
resultList.forEach((item, index) => {
接口({ data: item }).then((res) => {
resObj[item] = res.data;
if(index === resultList.length - 1) {
state = resObj;
}
})
})
有什么好的方法吗?循环中 index
的值并不是 0 1 2 3
给出的信息没有
resultList
的结构,但从代码来看item
应该是一个字符串,而不是一个数组,所以index === item.length - 1
这个条件可能存在逻辑失误。用
Promise.all
再用上 await