使用Promise.all实现,代码:
const getResultList = async () => {
try {
const [res1, res2] = await Promise.all([
dictionaryListAjax({ type: 'type1' }) as any,
dictionaryListAjax({ type: 'type2' }) as any,
]);
return [res1, res2];
} catch (error) {
console.error(error);
}
};
let value1 = [];
let value2 = [];
getResultList().then(([res1, res2]: any) => {
if (res1 && res1.length) {
const result = res1.map((val: any) => {
return val.name;
});
value1.value = result;
}
if (res2 && res2.length) {
const result = res2.map((val: any) => {
return val.name;
});
value2.value = result;
}
});
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。