Vue: 生命周期函数不支持 async 吗?

Created on 28 Dec 2017  ·  2Comments  ·  Source: vuejs/vue

What problem does this feature solve?

希望生命周期函数能够提供 async 的支持

What does the proposed API look like?

async create(){
await something()
}

mounted() {
// wait something done
}

Most helpful comment

@pz25925 只需要把async的方法都放在methods里面然后再在生命周期函数调用就可以了,这样也不会影响生命周期函数本身的正常执行。

All 2 comments

不支持,因为整个 diff 和 render 的算法都是基于组件生命周期同步执行的前提下的。而且任意一个组件的生命周期可能异步推迟最后的渲染完成是绝对不应该出现的设计。

@pz25925 只需要把async的方法都放在methods里面然后再在生命周期函数调用就可以了,这样也不会影响生命周期函数本身的正常执行。

Was this page helpful?
0 / 5 - 0 ratings