catch不到多个报错信息两个请求都返回了报错状态axios.all([this.getFormData(),this.getFormHead()]).then(axios.spread((fromDataResp,formHeadResp)=>{console.log("成功")})).catch(error=>{console.log(error,'只能打印第二条报错')})试过这样也不行axios.all([this.getFormData(),this.getFormHead()]).then(axios.spread((fromDataResp,formHeadResp)=>{console.log("成功")})).catch(axios.spread((fromDataerr,formHeaderr)=>{console.log(fromDataerr)//underfindconsole.log(formHeaderr)//underfind}))有大佬能指点一下吗???
2 回答
呼唤远方
TA贡献1856条经验 获得超11个赞
使用Promise.all只catch每一个函数。结果统一处理;!asyncfunction(){letres=awaitPromise.all([fun01().catch(err=>err),fun02().catch(err=>err),fun03().catch(err=>err),])console.log('res',res);//["成功:11111","失败:22222","成功:33333"]functionfun01(){returnnewPromise((resolve,reject)=>{setTimeout(()=>{resolve('成功:11111')},2000)})}functionfun02(){returnnewPromise((resolve,reject)=>{setTimeout(()=>{reject('失败:22222')},2000)})}functionfun03(){returnnewPromise((resolve,reject)=>{setTimeout(()=>{resolve('成功:33333')},2000)})}}();
添加回答
举报
0/150
提交
取消