vuex-module-decorators icon indicating copy to clipboard operation
vuex-module-decorators copied to clipboard

Could we invoke mutation directly in action?

Open Dimitri-WEI-Lingfeng opened this issue 4 years ago • 3 comments

Code assumed:

@Mutation
increment(){
  this.count++
}
@Action
act(){
  this.increment()  // instead of this.context.commit('increment')
}

I've seen this usage in "vue typescript admin template" and many other examples. Is that legal? But why it is not mentioned in the doc. I think it'is more convinient than commitment.

Dimitri-WEI-Lingfeng avatar Jun 12 '20 06:06 Dimitri-WEI-Lingfeng

From what I have seen it does not work, this was very confusing to me. We should at least update the docs to show how this needs to be done as not everyone wants to use @MutationAction

samtstern avatar Jun 17 '20 18:06 samtstern

This should be possible if you are using Dynamic Modules.

bangjelkoski avatar Jul 09 '20 09:07 bangjelkoski

@bangjelkoski I have used this approach in static modules without any issues

Pacheco95 avatar Apr 14 '21 20:04 Pacheco95