morteza mortezaie
morteza mortezaie

Reputation: 1564

Vuex module decorator : how to call mutation from component

I have this store

store/r2o.ts

import { Module, VuexModule, Mutation } from 'vuex-module-decorators'
import { IR2O } from '~/models/R2O'

@Module({
  name: 'r2o',
  namespaced: true
})
export default class R2O extends VuexModule {
  r2os: Array<IR2O> = []
  @Mutation
  set(p: Array<IR2O>) {
    this.r2os = p
  }
}

I need to call this mutation in my component how can i do it ??

Upvotes: 1

Views: 649

Answers (1)

Florin Relea
Florin Relea

Reputation: 513

If you want to do it directly

this.$store.commit('r2o/set', [])

If you want to use vuex-class

import { namespace } from 'vuex-class'

...


@namespace('r2o').Mutation('set') setR2o: (p: Array<IR20>) => any


myMethod() {
  this.setR2o([])
}

Upvotes: 1

Related Questions