Vuex: Access State From Another Module Vuex: Access State From Another Module vue.js vue.js

Vuex: Access State From Another Module


state references local state and rootState should be used when accessing the state of other modules.

let session = context.rootState.instance.session;

Documentation: https://vuex.vuejs.org/en/modules.html


from an action :

'contacts:update' ({ commit, rootState }) {    console.log('rootState', rootState.users.form)    ......  },


For me I had vuex modules, but needed a mutation to update STATE in a different file. Was able to accomplish this by adding THIS

Even in the module you can see what global state you have access to via console.log(this.state)

const mutations = {MuteChangeAmt(state, payload) {//From user module; Need THIS keyword to access global statethis.state.user.payees.amount = payload.changedAmt; }}


matomo