I'd like to create a component that I can instantiate multiple times pointing at (loading its data from) different vuex-namespaces. The component will gets most of its data from Vuex. So say I have a Person component, I could instantiate many copies of the Person component, based on different paths into vuex.
The best way I've figured out how to do this is to pass a vuex path as a prop, but then I don't know how to use mapGetters and friends, because they require a namespace at the time the .vue file is instantiated.
I'd appreciate insight into the best "Vue way" to structure this. Here's the closest approach I've figured out at the moment.
Person.vue:
<template>
<div>person {{name}} is {{age}} years old</div>
</template>
<script>
export default {
props: ['vuexNamespaceToLoadFrom'],
// FIXME: how do I do a mapGetters with a dynamic namespace that's
// set through props???
// I can't do the following since props aren't in scope yet :-(
...mapGetters(this.vuexNamespaceToLoadFrom, [ 'name', 'age'])
}
</script>
Instantiating a few Person multiple-use components that load their properties from different vuex-namespaces:
<Person vuex-namespace-to-load-from="api/jim">
<Person vuex-namespace-to-load-from="api/someotherpath/rachid">
<div>
<Person vuex-namespace-to-load-from="api/alternatepeople/grace">
</div>