共计 645 个字符,预计需要花费 2 分钟才能阅读完成。
Promise 用法
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); // 申请接口失败
});
Promise.all 用法
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/
正文完