📜  我可以在 vue js 中使用 promise.all 条件吗 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:18.652000             🧑  作者: Mango

代码示例1
const promises = [];

if(true) {
   const promise1 = fetch('https://jsonplaceholder.typicode.com/posts/1').then(res => ({ res: res, promise: 'promise1' }));
   promises.push(promise1);
}

if(false) {
   const promise2 = fetch('https://jsonplaceholder.typicode.com/posts/2').then(res => ({ res: res, promise: 'promise2' }));
   promises.push(promise2);
}

Promise.all(promises).then(res => console.log(res));
 Run code snippet