if (dealFileList.value && topicFileList.value && accountFileList.value) {
state.btnLoading = true;
const [res01, res02, res03] = await Promise.all([
handleImportFile(dealFileList.value, '/economic/economyDeal/import'),
handleImportFile(topicFileList.value, '/economic/economyMain/import'),
handleImportFile(accountFileList.value, '/economic/economyAccount/import'),
]).catch((error) => {
console.log('output-> error::: ', error)
})
if (res01 && res02 && res03) {
state.btnLoading = false;
onCancelClick();
resetFile();
message.success('文件上传成功')
}
}
案例
const initDictOpts = () => {
const req01 = getDicByType({typeCode: 'assignLevel'});
const req02 = getDicByType({typeCode: 'verificationResponsibleUnit'});
const req03 = getDicByType({typeCode: 'involvedUnit'});
const req04 = getDicByType({typeCode: 'accountableSituation'});
// 使用Promise.all同时执行多个请求
Promise.all([req01, req02, req03, req04])
.then((responses: any) => {
// 所有请求都成功完成
console.log('output-> response::: 【initDictOpts】', responses)
dictObj.assignLevelOpts = responses[0].data;
dictObj.verificationResponsibleUnitOpts = responses[1].data;
dictObj.involvedUnitOpts = responses[2].data;
dictObj.accountableSituationOpts = responses[3].data;
})
.catch(error => {
// 请求中的任何一个失败都会触发catch
console.error(error);
});
}
标签:const,responses,并行,value,dictObj,案例,Promise,error
From: https://www.cnblogs.com/openmind-ink/p/17851955.html