#Way to persist data on pinia store

7 messages · Page 1 of 1 (latest)

silent raven
#

Hello, really new to Nuxt3 (I'm used to work with Vue3/Vite)
I'm looking for a way to persist data on pinia store when refreshing the page, I've tried multiples libraries such as:

but it leads to the same error:
No "exports" main defined in [...]/node_modules/@nuxt/kit/package.json

I've also checked the useLocalStorage option (https://github.com/vuejs/pinia/issues/309) but I need my whole stores to be persisted, not only some values

Can anyone help me?

silent raven
#

up Sadge

manic cobalt
#

You can do it using localstorage. Use a specific key for every store that you want to persist and save the state of that store as an object. You can create a utility function for de/serializing and configure it to your needs

#

Local storage has a limit of 10mb tho

#

You can go to the github page for the pinia plugin and look up the implementation. There isn't much there

vivid ibex
#

You could also use the VueUse library and useLocalStorage within your pinia store. if you are using setup within your pinia store then when exporting the state you can use the skipHydration() helper function. This is what worked for me.

plucky nimbus