作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在动态注册 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
}
}
...
Cannot read property 'namespace' of undefined
最佳答案
在这里解决 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)
})
})
}
}
关于Vuex - 绑定(bind)助手中的动态命名空间(mapState,...),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55927452/
假设我们有一个非常复杂的任务。我知道如果我们使用一个线程,那么实际上我们将使用一个内核,但是如果我将任务划分为与处理器内核数量相等的线程,程序是否一定会在所有内核上运行? 或者使用的线程数和内核数与
我是一名优秀的程序员,十分优秀!