Skip to content

Latest commit

 

History

History
29 lines (24 loc) · 490 Bytes

vuex-dispatch-between-stores.md

File metadata and controls

29 lines (24 loc) · 490 Bytes

Vuex: Dispatch Between Stores

Instead of writing this.$store.dispatch('otherStore/action', payload),

const state = {
  thing: null,
};
    
const mutations = {
  SET_THING (state, payload) {
    state.thing = {...payload}
  },
};

const actions = {
  updateThing ({ commit, dispatch }, payload) {
    commit('SET_THING', payload)
    dispatch('otherStore/action', payload, {root: true})
  }
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
}