Ale*_*x T 3 vue.js vuex vuejs2 vuex-modules
VueX 中是否可以让一个方法等待,mounted()直到执行其他组件中的某些突变?
因为有时该突变是在之前执行的,有时是在之后执行的,因此我想知道在安装组件时是否可以在运行后等待:
mounted() {
// await MutationName
this.columnItemsInit();
}
Run Code Online (Sandbox Code Playgroud)
小智 5
您可以使用store.subscribe方法订阅突变
mounted() {
let unsubscribe = null
unsubscribe = this.$store.subscribe(({ type }) => {
if (type === 'MutationName') {
this.columnItemsInit()
unsubscribe() // So it only reacts once.
}
})
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7787 次 |
| 最近记录: |