Vuex Call Getter

Posted on  by admin

In addition to commit, actions has default injected parameters which are dispatch, getters and rootGetters.

So you can simply write; . sendDataToServer({ commit, getters }, payload) to access getters.

You have access to getters inside an action:. In the action, you see the first parameter has {commit} in it.


Similarly, you can pass {commit, state}. This way, you can directly access the state.data. I think in your example, you would want to do the action because you can call the mutation from inside action itself using commit('setData').


The first parameter is there for you to use state and mutation as you prefer.

Personally, I have only worked on projects where you do the action first and do mutation to store it in the app.