我要访问state.session
的instance.js
从records_view.js
。这是如何完成的?
商店/模块/instance.js
const state = {
// This is what I want to access in records_view.js
session: {}
};
const getters = {
sessionGetter: state => state.session
};
商店/模块/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
);
}
};
这是为了增加一些上下文。
商店/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
}
});
对我来说,我有vuex模块,但需要进行更改以更新其他文件中的STATE。能够通过添加此来完成此操作
即使在模块中,您也可以通过console.log(this.state)查看您可以访问的全局状态