1、async 函数返回一个Promise对象
2、await 就是异步等待,后面应该跟一个Promise对象,如果不是Promise对象,那么会被转成一个立即 resolve 的Promise
3、await 等待的是一个Promise对象,会将Promise对象的resolve状态的值返回,而不是返回Promise对象
onLoad: async function (options) { const aa = await this.promise1() //没有await console.log(aa) }, promise1(){ return new Promise((resolve, reject) => { resolve('aaaa') }) },
输出 Promise对象
Promise {<resolved>: "aaaa"}
onLoad: async function (options) { const aa = await this.promise1() //有await console.log(aa) }, promise1(){ return new Promise((resolve, reject) => { resolve('aaaa') }) },
输出 Promise对象resolve的值
aaaa