【js】处理promise.all在有一个函数失败的时候也能继续执行

核心就是在调用.all的时候,map全部函数,就算失败了也给一个返回值,确保函数全部执行

Promise.all([fn,fn1...].map(p=>{
    
    
	//.then返回需要的东西 .catch返回一些错误信息
	return p.then(e=> {
    
    
		 	return p
		}).catch(err=> return '错误了')
})).then( res => {
    
    
	//拿到需要的数据	
}).catch(reason => {
    
    
	console.log(reason)
})

猜你喜欢

转载自blog.csdn.net/weixin_50636536/article/details/128555201