关于map和Promise.all搭配使用
场景一:
// 注意:此时map会发送请求 Promise.all只为拿到并发的结果
const requestBus = rawData.map(v => getfeedbackfielddata({ table_name: v.rule.rule.from.table_name_en }))
Promise.all(requestBus).then(res=>{
// res 为请求数据的集合
})
场景二:
const handleRequest = async () => {
// 获取所有请求的结果
const resList = await Promise.all(
arr.map(async item => {
const res = await request(item );
// 获取本次请求的结果
return res;
})
);
return resList;
};
// 使用
const res = await handleRequest();

浙公网安备 33010602011771号