async a(){
const result = await this.b();
// async 返回值会封装成一个promise
return result
},
async b() {
return 1
},
async test() {
console.log(this.a()) //async 返回的是一个promise,打印:Promise {<pending>}
this.a().then(res=>{
console.log(res) //1
})
},
async,await简单用例
最新推荐文章于 2023-09-27 20:24:45 发布