async function a() { let a1 = await new Promise(function(resolve, reject) { var num = 5; return num; }); let a2 = await new Promise(function(resolve,reject){ //我想在这里拿到a1的返回值 }); let a3 = await a2() //我想拿到a2的返回值}
1 回答
绝地无双
TA贡献1946条经验 获得超4个赞
async function a() {
let a1 = await new Promise(function(resolve, reject) {
const num = 5;
resolve(num)
});
let a2 = await new Promise(function(resolve,reject){
//我想在这里拿到a1的返回值
console.log(a1) // 5
resolve(a1)
});
let a3 = await a2 //我想拿到a2的返回值
console.log(a3) // 5
}
a()
这样就可以了啊,希望能帮到你,Promise需要把结果放在resolve里面 而不是 return,
另外你都用async await
就不要用var
了吧,箭头函数也可以搞起来 代码可以简洁不少
添加回答
举报
0/150
提交
取消