Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should a component commit a mutation directly?

Tags:

vuejs2

vuex

In the Mutations chapter, you can see an example that uses mapMutations to map mutations to component methods.

It also says that

You can commit mutations in components with this.$store.commit('xxx')

So the question comes, is committing a mutation directly from a component (not through an action) fine in vuex?

If it is, then this diagram may need to update:

enter image description here

Should I keep using the mapMutations method?

like image 669
Sandwell Avatar asked Jan 22 '26 04:01

Sandwell


1 Answers

As far as I understood, actions are mainly used for asynchronous operations which might comprise multiple mutations. So yes, it's ok to directly use mutations, that's what they are made for. Only when you have more complex workflows involving multiple mutations you should wrap them in an action.

like image 173
dr_barto Avatar answered Jan 24 '26 11:01

dr_barto