async created () { await setTimeout(()=>{ console.log(1)
},5000);
}, async mounted () { console.log(2)
}在vue中给created使用async await,还是会先输出2,而不是等1输出完?
2 回答
回首忆惘然
TA贡献1847条经验 获得超11个赞
可以变相达到这个目的
async created () { this.create_promise = new Promise(resolve=>this.create_promise_resolve=resolve); setTimeout(()=>{ console.log(1); this.create_promise_resolve(); },1000) }, async mounted () { await this.create_promise; console.log(2) }
添加回答
举报
0/150
提交
取消