NuxtN
Nuxt2y ago
MolakDul

Pinia and Nuxt Layouts

Hey! Quick question about Pinia.

I have a very simple user store with a state and a "fetch" action that populates this state via a GQL request.
I trigger this fetch in the top-level component app.vue:

const userStore = useUserStore();
userStore.fetch();


But when I want to access the state in my default layout to display the user's photo like this:

const userStore = useUserStore();
console.log(userStore.photo);


Well, the console.log is empty... Yet everything is well initialized if I inspect with NuxtDevTools.

What is the issue with layouts ? Because i'm using the state of this very same store in a page and display them without any issue ...

Any idea?
Was this page helpful?