await把Promise解析为普通对象,async函数return的返回值是promise对象,await后转化为普通Object
怎么实现axios的then执行完再执行后续程序,并return返回的值文章目录前言总结前言await 会等到promise的then执行完之后,再执行后续程序async function aa(){let resData;await axios.post(url,data).then(res=>{resData = res;})return resData}总结踩坑路漫漫长@~@...
·
async函数return的是Promise,await Promise后得到Object
文章目录
前言
1、函数return的返回值Object,await后得到的是Object
function aa(){
let num = 5
return num;
}
async function bb (){
let num1 = aa();
let num2 = await aa();
console.log(num1);
console.log(num2);
}
bb();
2、async函数return的返回值是Promise,await后得到是Object
async function aa(){
let num = 5
return num;
}
async function bb (){
let num1 = aa();
let num2 = await aa();
console.log(num1);
console.log(num2);
}
bb();
3、函数直接return Promise,await后得到是Object
function aa(){
let num = 5
return new Promise((resolve,reject)=>{
resolve(num);
});
}
async function bb (){
let num1 = aa();
let num2 = await aa();
console.log(num1);
console.log(num2);
}
bb();
综上 async函数return出来的是promise对象,需要await后方可转化为普通Object
总结
踩坑路漫漫长@~@
更多推荐
已为社区贡献2条内容
所有评论(0)