I have modularized my Vuex store and need child-components to be able to access data/use the same stores as their parent component.
Here's what I've tried:
<!-- 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>
And here's the error I'm getting
Uncaught TypeError: Cannot read property 'vuexStore' of undefined
I've been passing down props, but the prop juggling is getting chaotic and it would be much easier if I could just specify which store a component should use.
I also not able to specify the store directly in the child component since ParentTwo.vue may use a different store such as services/cases
.
Anyone have any idea why this wouldn't work. I'm open to alternative solutions as well.
...mapState(this.vuexStore, ...)
it should encounter wrong context issue – Myrlemyrlene