有没有人遇到过这个问题哈!axios.all 多个请求同时报错 catch不到求指导!

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)//underfind
console.log(formHeaderr)//underfind
}))
有大佬能指点一下吗???
哆啦的时光机
浏览 1512回答 2
2回答

眼眸繁星

使用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)})}}();
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript