Vuex: Access State From Another Module

后端 未结 6 778
走了就别回头了
走了就别回头了 2021-01-30 08:12

I want to access state.session in instance.js from records_view.js. How is this accomplished?

store/modules/instance.js

6条回答
  •  盖世英雄少女心
    2021-01-30 08:43

    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 state
    this.state.user.payees.amount = payload.changedAmt;
     }
    }
    

提交回复
热议问题