Skip to content
This repository was archived by the owner on Aug 31, 2025. It is now read-only.

Commit c9e47ea

Browse files
authored
📝 add nuxt usage docs
1 parent 8416ebf commit c9e47ea

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,23 @@ The config above will only persist the `nested.data` property in `sessionStorage
101101

102102
It will also execute the `beforeRestore` and `afterRestore` hooks respectively _before_ and _after_ hydration.
103103

104+
### Usage with Nuxt
105+
106+
You can use Nuxt's [`Cookies`](https://v3.nuxtjs.org/docs/usage/cookies/) and `useCookie` to define a `storage` to persist your stores with SSR.
107+
108+
```ts
109+
import { defineStore } from 'pinia';
110+
111+
export const useUserStore = defineStore('ssr', {
112+
persist: {
113+
storage: {
114+
getItem: (key) => { return useCookie(key, { encode: x => x, decode: x => x }).value },
115+
setItem: (key, value) => { useCookie(key, { encode: x => x, decode: x => x }).value = value },
116+
},
117+
},
118+
})
119+
```
120+
104121
## ⚠️ Limitations
105122

106123
### __References do not persist__

0 commit comments

Comments
 (0)