我正在动态注册 vuex 存储模块
store.registerModule('home.grid', GridStore)
然后在组件中:
export default {
name: 'GridComponent',
props: {
namespace: {
type: String,
required: true
},
computed: {
...mapState(this.namespace, ['filter']) // doesn't work
filter() { // more verbose but working
return this.$store.state[this.namespace].filter
}
}
...
但我收到错误:
无法读取未定义的属性“命名空间”
任何想法 ?
问题最初是从“gabaum10”这里提出的https://forum.vuejs.org/t/vuex-dynamic-namespaces-in-mapstate-mapactions/28508 https://forum.vuejs.org/t/vuex-dynamic-namespaces-in-mapstate-mapactions/28508
在这里解决https://github.com/vuejs/vuex/issues/863#issuecomment-329510765 https://github.com/vuejs/vuex/issues/863#issuecomment-329510765
{
props: ['namespace'],
computed: mapState({
state (state) {
return state[this.namespace]
},
someGetter (state, getters) {
return getters[this.namespace + '/someGetter']
}
}),
methods: {
...mapActions({
someAction (dispatch, payload) {
return dispatch(this.namespace + '/someAction', payload)
}
}),
...mapMutations({
someMutation (commit, payload) {
return commit(this.namespace + '/someMutation', payload)
})
})
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)