Pinia
You can use Vike with Pinia.
This page documents how to manually integrate Pinia.
You can use
vike-vue-pinia
instead of manually integrating Pinia yourself.
Initial state
When using a store such as Pinia, your components don't access fetched data directly: your components only access the store.
Integration example:
- Initialize Pinia with
app.use()
insideonCreateApp()
. - Get the initial SSR state of the store and make it available as
pageContext.initialStoreState
.For example in
onAfterRenderHtml()
, oronRenderHtml()
if you don't usevike-react
/vike-vue
/vike-solid
.See also: API >
pageContext
> Custom. - Make
pageContext.initialStoreState
available on the client-side.See API >
passToClient
. - Initialize Pinia on the client-side with
pageContext.initialStoreState
.For example in
onBeforeRenderClient()
, oronRenderClient()
if you don't usevike-react
/vike-vue
/vike-solid
.
See also:
Examples
- 2024.06
vike-vue-pinia
-
2024.03 GitHub >
IT4Change/boilerplate-frontend
-
2023.10 GitHub >
brillout/vike-with-pinia