function getData1(){
return new Promise((resolve, reject) => {
setTimeout(()=>{
console.log('第1条数据加载成功')
resolve('data1')
},1000)
})
}
function getData2(){
return new Promise((resolve, reject) => {
setTimeout(()=>{
console.log('第2条数据加载成功')
resolve('data2')
},100)
})
}
function getData3(){
return new Promise((resolve, reject) => {
setTimeout(()=>{
console.log('第3条数据加载成功')
reject('data3 err')
},1000)
})
}
let p = Promise.all([getData1(),getData2(),getData3()])
p.then((resolve)=>{
console.log('resolve',resolve)
},(reject)=>{
console.log('reject',reject)
})
两者唯一区别在于是promise.all还是promise.race,前者不管速度如何,只要有一个失败就是失败,后者最先完成的是什么就是什么