let request = new Promise((resolve, reject) => {
// 表达式
if (true) {resolve({ age: 20});
} else {reject('申请接口失败');
}
});
request
.then(res => {console.log('res', res); // {age: 20}
})
.catch(res => {console.log('res2', res); // 申请接口失败
});
let requestA = new Promise(resolve => {setTimeout(() => {resolve({ requestA: 20});
}, 1000 * 2);
});
let requestB = new Promise(resolve => {resolve({ requestB: 50});
});
let requestAll = Promise.all([requestA, requestB]).then(res => {console.log('res', res); // [{requestA: 20}, {requestB: 50}]
});
- 【继续保护 / 更新 500+ 前端面试题 / 笔记】https://github.com/noxussj/In…
- 【大数据可视化图表插件】https://www.npmjs.com/package…
- 【利用 THREE.JS 实现 3D 城市建模(珠海市)】https://3d.noxussj.top/