【发布时间】:2021-01-24 23:11:18
【问题描述】:
我已经模块化了我的 Vuex 存储,并且需要子组件能够访问数据/使用与其父组件相同的存储。
这是我尝试过的:
<!-- ParentOne.vue -->
<template>
<div>
<child-component
vuex-store="services/opportunities"
/>
</div>
</template>
<script>
import ChildComponent from '@/components/services/child-components/ChildComponent';
import { mapActions, mapState, mapGetters } from 'vuex';
export default {
components: {
'child-component': ChildComponent,
},
computed: {
...mapState('services/opportunities', {
statusListOpportunities: 'statusListOpportunities',
}),
}
}
</script>
<!-- ChildComponent.vue -->
<template>
<div>
<!-- Content -->
</div>
</template>
<script>
import { mapActions, mapState, mapGetters } from 'vuex';
export default {
props: {
vuexStore: {
type: String,
},
},
computed: {
...mapState(this.vuexStore, {
statusListOpportunities: 'statusListOpportunities',
}),
}
}
</script>
这是我遇到的错误
未捕获的类型错误:无法读取未定义的属性“vuexStore”
我一直在传递道具,但是道具杂耍变得越来越混乱,如果我可以指定组件应该使用哪个存储会容易得多。
我也无法直接在子组件中指定存储,因为 ParentTwo.vue 可能使用不同的存储,例如 services/cases。
任何人都知道为什么这不起作用。我也愿意接受替代解决方案。
【问题讨论】:
-
...mapState(this.vuexStore, ...)它应该遇到错误的上下文问题
标签: vue.js vue-component vuex vuex-modules