在我的 ContactForm 组件中,我有 2 个计算的 mapGetter
computed: {
...mapGetters(["language"]),
...mapGetters("authentication", ["loading"]),
Run Code Online (Sandbox Code Playgroud)
第一个在我的 stoe/getters.js 中定义
export const language = state => {
return state.language;
};
Run Code Online (Sandbox Code Playgroud)
第二个是在我的 store/modules/authentication.js 中定义的
const authentication = {
namespaced: true,
getters: {
user: state => {
return state.user
},
loading: state => {
return state.loading
}
Run Code Online (Sandbox Code Playgroud)
},
我正在尝试模拟我的 Vuex 商店,这对于第一个“语言”来说很容易,
export const storeMock = Object.freeze({
state: {},
actions: {},
getters: {
language: () => { . // <= FINE
return "en";
},
authentication: { . // <= . WRONG
loading: () => {
return false;
}
}
}
})
Run Code Online (Sandbox Code Playgroud)
但是我应该如何模拟“身份验证”模块中的第二个“加载”?
如果您在应用程序中控制台登录商店,命名空间的 getter 的键为namespace/getterName,所以我认为这应该有效
export const storeMock = Object.freeze({
state: {},
actions: {},
namespaced: true,
getters: {
language: () => { // <= FINE
return "en";
},
'authentication/loading' : () => {
return false;
}
}
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3408 次 |
| 最近记录: |