典型的Promise模拟应用
async function getxx() {
return await new Promise((resolve, reject) => {
// 异步操作
setTimeout(() => {
if (5==6) {
resolve('Promise 延迟 2 秒后 resolve');
} else {
reject("失败");
}
}, 2000);
});
}
async function wo() {
return await getxx(); // 这里的参数一般就是访问地址了
}
wo().then(value => {
// 成功时的回调函数
console.log(value);
}, error => {
// 失败时的回调函数
console.log(error);
});