Consider the following Widget component.
<template>
<component :is="name" />
</template>
<script>
import { mapActions } from 'vuex';
export default {
props: {
name: {
type: String,
required: true
}
},
created() {
this.addWidget(this.name);
},
methods: {
...mapActions({
addWidget: 'widgets/add'
}) // adds widget name to an array
}
};
</script>
I want to have multiple components like this one all over the page. I need to be able to gather all of the component names so I can fetch the relevant data for them.
My current idea is to add the component name to the store when the created
hook fires.
That works just fine, but my problem is that I can't find a way to dispatch
a Vuex
action to fetch the data once all of the components have been created. I tried using various hooks to no avail since none of them seems to have Vuex
access.
Am I missing something? Is there some kind of hook that fires after all of the components have been created (SSR
) that has Vuex
access. Or maybe there's some better way to achieve what I've been trying to do?