Call getter from another store module
-
I found lots of posts on google about this subject but couldn’t understand how to make it to work.
I also tried lots of different situations and none of them worked.I have a store with modules in a sub-folder
from one of the modules I need to call a getter from another module
this is the module where the getter belongsimport { SessionStorage } from 'quasar' import { wsbtms } from '../../boot/axios' const state = { objAtrativosLista: {}, objAtrativo: {}, cdgbtms_atrativo_atual: '' } const mutations = { } const actions = { } const getters = { gtAtrativoAtual: (state) => { return state.cdgbtms_atrativo_atual } } export default { namespaced: true, state, mutations, actions, getters }
(I cleaned the file and left only the important lines)
On the other module I need to call the gtAtrativoAtual getter
import { SessionStorage } from 'quasar' import { wsbtms } from '../../boot/axios' import store from '../stAtrativos' // **** should I import the module or the entire store ?? ***** const state = { objEmissoresLista: {}, objEmissor: {}, objAgentesLista: {}, objAgente: {}, objAgentesListaCache: {}, cdgbtms_emissor_atual: '' } const mutations = { } const actions = { async actAgentesListaCache ({ commit }, payload) { console.log('iiiii', store) console.log('xxxxx', this.$store['atrativos/gtAtrativoAtual']) console.log('rrrrr', store.getters.gtAtrativoAtual) let json = { 'dados': { 'head': { 'servico': 'agentes_lista', 'chave': SessionStorage.getItem('login_sessao').chave }, 'data': { 'cdgbtms_agencia': payload.cdgbtms_agencia } } } let jtext = JSON.stringify(json) let retorno = await wsbtms.post( wsbtms.defaults.baseURL, jtext) .then((response) => { if (response.data.info[0].registros > 0) { commit('mutAgentesListaCache', response.data) commit('mutCdgbtmsEmissorAtual', payload) } else { } return response }) return retorno } } const getters = { } export default { namespaced: true, state, mutations, actions, getters }
And it logs like this:
I tried many ways of doing it. Importing all the store, just the module, … but it doesn’t work for me.
Is it possible to do it ? I have lots of global data that I need to access from other modules.
In Vue files it goes well. I import it with mapGetters and it works very well, but in .js files I can’t make it work.Someone can help me with this ??
Tks
-
@Pedro said in Call getter from another store module:
getters.gtAtrativoAtual
include
rootGetters
in the first param of your action.
like so:async actAgentesListaCache ({ commit, rootGetters }, payload) { ... console.log('rrrrr', rootGetters['atrativos/gtAtrativoAtual']) ... }
-
Works perfect. Thank you