在ContactForm组件中,我有2个计算的mapGetters
computed: {
...mapGetters(["language"]),
...mapGetters("authentication", ["loading"]),
第一个定义在我的stoe / getters.js
中export const language = state => {
return state.language;
};
第二个在我的store / modules / authentication.js中定义
const authentication = {
namespaced: true,
getters: {
user: state => {
return state.user
},
loading: state => {
return state.loading
}
},
我正在尝试模拟我的Vuex存储,对于第一个“语言”来说很容易,
export const storeMock = Object.freeze({
state: {},
actions: {},
getters: {
language: () => { . // <= FINE
return "en";
},
authentication: { . // <= . WRONG
loading: () => {
return false;
}
}
}
})
但是我应该如何从“身份验证”模块中模拟第二个“加载”?
答案 0 :(得分:1)
如果您在应用程序中控制台登录存储区,则命名空间的getter的密钥为namespace/getterName
,所以我认为这应该可行
export const storeMock = Object.freeze({
state: {},
actions: {},
getters: {
language: () => { // <= FINE
return "en";
},
'authentication/loading' : () => {
return false;
}
}
})