Ich möchte auf state.session
in instance.js
von records_view.js
zugreifen. Wie wird das erreicht?
store/modules/instance.js
const state = {
// This is what I want to access in records_view.js
session: {}
};
const getters = {
sessionGetter: state => state.session
};
store/modules/records_view.js
const actions = {
getSettingsAction (context, props) {
// This is how I'm trying to access session, which doesn't work
let session = context.state.instance.session;
Api(
context,
{
noun: props.noun,
verb: 'GetRecordsViewSettings',
orgUnitKey: _.has(session, 'orgunit.key') ? session.orgunit.key : '',
data: {}
},
props.callback
);
}
};
Dies ist für ein wenig zusätzlichen Kontext.
store/index.js
import Vue from 'vue';
import Vuex from 'vuex';
import * as actions from './actions';
import * as getters from './getters';
import * as types from './mutation-types';
import instance from './modules/instance';
import recordsView from './modules/records_view';
Vue.use(Vuex);
export default new Vuex.Store({
state,
actions,
getters,
mutations,
modules: {
instance,
recordsView
}
});
state
verweist auf den lokalen Status und rootState
sollte beim Zugriff auf den Status anderer Module verwendet werden.
let session = context.rootState.instance.session;
Dokumentation: https://vuex.vuejs.org/de/modules.html
von einer Aktion:
'contacts:update' ({ commit, rootState }) {
console.log('rootState', rootState.users.form)
......
},
Für mich hatte ich Vuex-Module, brauchte aber eine Mutation, um STATE in einer anderen Datei zu aktualisieren. Konnte dies durch Hinzufügen von DIESEM erreichen
Sogar im Modul können Sie sehen, auf welchen globalen Status Sie über console.log (this.state) zugreifen können.
const mutations = {
MuteChangeAmt(state, payload) {
//From user module; Need THIS keyword to access global state
this.state.user.payees.amount = payload.changedAmt;
}
}