How to call action inside action in Vuex
this is how i got it to working :)
import Vue from 'vue'export const fetchUsers = ({ dispatch, state }) => { Vue.http.get('http://localhost:3000/api/v1/users').then((response) => { dispatch('SET_USERS', response.data) }, (response) => { dispatch('SET_USERS', []) console.log(response) })}export const updateUser = ({ dispatch, state }, user) => { Vue.http.patch('http://localhost:3000/api/v1/users/' + user.id, {user: user}).then((response) => { fetchUsers({dispatch}) }, (response) => { dispatch('SET_USERS', []) console.log(response) })}
When you console.log('this', this)
inside of store module, you can see dispatch listed in that context. so you can use it like so.:
// inside of store/test.js moduleexport const state = () => ({ test: 'somestate'})export const mutations = { ACTION_TWO(state, data) { state.test = data; }}export const actions = { actionOne({ commit }, value) { this.dispatch('test/actionTwo', value); // moduleName/action }, actionTwo({ commit }, valueToCommit) { commit('ACTION_TWO', valueToCommit); }}