以下是1种可能的解决方案:
export const store = new Vuex.Store({
state : {
clientConfigs :{
"1": clientConfig1,
"2": clientConfig2
},
clientId: "1"
},
getters: {
currentClientConfig: state => {
return state.clientConfigs[state.clientId]
}
},
mutations: {
setClientId (state, newValue) {
state.clientId = newValue
}
}
});
在您的组件中,您可以通过以下方式访问配置
this.$store.getters.currentClientConfig
要更新
clientId
,可以使用突变。在组件中,可以使用
this.$store.commit('setClientId', yourNewClientId)