ES6-Promise.all()使用

Promise.add 方法:将多个 promise 实例,包装成一个新的 promise 实例。

const p = Promise.all([p1, p2, p3]);

接受一个数组作为参数,p1, p2, p3 都是 promise 实例,

const p1 = new Promise((resolve, reject) => {
  resolve('hello');
}).then(res => res);

const p1 = new Promise((resolve, reject) => {
  throw new Error('报错');
}).then(res => res);

Promise.all([p1, p2])
.then(res => console.log(res))
.catch(e => console.log(e))

// Error : 报错
原文地址:https://www.cnblogs.com/zhangym118/p/10087918.html