Is there a way to incorporate asyncData
into a layout or component even though it seems to be forbidden?
The reason I'm asking is because my sidebar component is used in the default layout, and I want to utilize asyncData
to display data fetched from the backend. However, if I were to use Vuex to fetch the data, I am unsure how to make it global and accessible on every page.
Annotating my layout component:
@Component({
components: {
LeftDrawer
},
async asyncData({ app }) {
const latestPosts = await app.$axios.get(`/posts/latest`);
return {
latestPosts: latestPosts.data,
};
}
})