Reputation: 115
Is there any way in vuex
to stop a mutation after commit? For redux
, if next
is not called in middleware, then we can say that the action is stopped
Upvotes: 3
Views: 1073
Reputation: 55634
No, you cannot stop a mutation after commit.
If your application needs to prevent a commit in only certain circumstances, you could put that logic in an action:
mutations: {
INCREASE_FOO(state) {
state.foo++;
}
},
actions: {
increaseFoo({commit}) {
if (someCondition) {
commit('INCREASE_FOO');
}
}
}
Then, when dispatching the action via this.$store.dispatch('increaseFoo')
, the commit will only fire under the specified condition.
Upvotes: 2