如何停止 Vuex 中的提交突变
how to stop commited mutation in Vuex
vuex
中有什么方法可以在提交后停止突变吗?对于redux
,如果在中间件中没有调用next
,那么我们可以说动作停止了
不,您不能在提交后停止变更。
如果您的应用程序只需要在特定情况下阻止提交,您可以将该逻辑放入操作中:
mutations: {
INCREASE_FOO(state) {
state.foo++;
}
},
actions: {
increaseFoo({commit}) {
if (someCondition) {
commit('INCREASE_FOO');
}
}
}
然后,当通过 this.$store.dispatch('increaseFoo')
调度操作时,提交只会在指定条件下触发。
vuex
中有什么方法可以在提交后停止突变吗?对于redux
,如果在中间件中没有调用next
,那么我们可以说动作停止了
不,您不能在提交后停止变更。
如果您的应用程序只需要在特定情况下阻止提交,您可以将该逻辑放入操作中:
mutations: {
INCREASE_FOO(state) {
state.foo++;
}
},
actions: {
increaseFoo({commit}) {
if (someCondition) {
commit('INCREASE_FOO');
}
}
}
然后,当通过 this.$store.dispatch('increaseFoo')
调度操作时,提交只会在指定条件下触发。