2

I've a module named "csv", to handle csv files, and a vue-tables-2 with vuex:

Store structure:

-store
 -modules
   -csv.js
 -index.js

index.js:

Vue.use(Vuex)

    const store = new Vuex.Store({
        modules: {
            commons,
            ldap,
            csv <---- I want to execute the mutation in this module
        },
        mutations: {
            ["csvTable/ROW_CLICK"](state, data){
               <---- but now it's running here
            },
        }
    })

csv.js

// initial state
const state = {
    //...
}

// getters
const getters = {
    //...
}

// mutations
const mutations = {
    ["csvTable/ROW_CLICK"](state, data){
       < ---I want to execute the mutation here
    }
}

export default {
   //...
}

So I want to know how can I execute the ROW_CLICK mutation in the csv module.

I thought I could do it like this:

index.js:

  ["csvTable/ROW_CLICK"](state, data){
       this.commit(csv/ROW_CLICK, data);
  },

But I do not think it's the best way to do it.

Thank you.

Fabio Venturi Pastor
  • 2,519
  • 3
  • 19
  • 32

1 Answers1

1

Learn to use actions.It is recommended to execute your mutations through actions always.

In csv.js add an action like:

   actions: {
     callMutation({commit}, pass_property){ //pass_property is passed to action
       commit('the_mutation_you_want_to_Call',pass_property)
     }
   }

Also the commit object is required to actions to commit mutation.But, if you want, in actions you can use the getters and state as well.See below:

Example:

  actions: {
    actionName({commit,getters,state}) {}
  }
Roland
  • 24,554
  • 4
  • 99
  • 97