methods: { start () { console.log(this.test()) // Promise {<fulfilled>: 123} }, async test () { return 123 // return Promise.resolve(123) // return new Promise((res, rej) => { // res(123) // }) } }
若是直接执行this.test()(无论直接return 123仍是return Promise.resolve(123)),都将返回Promise对象(会被包装为一个当即resolve的Promise对象);async
拿到return值的方式:
1.Promise.thenthis
start () { this.test().then(res => { console.log(res) // 123 }) }
2.async-awaitcode
async start () { console.log(await this.test()) // 123 }