Vuex:来自另一个模块的访问状态
2022-08-30 04:16:19
我想从 中访问。这是如何实现的?state.session
instance.js
records_view.js
存储/模块/实例.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
);
}
};
这是为了增加一点上下文。
存储/索引.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
}
});