Features
- Persist Pinia stores with a friendly API inspired by
vuex-persistedstate. - Highly customizable (storage, serializer, paths picking/omitting).
- Out of the box SSR-friendly support for
Nuxt. - Very smol (<2kB minzipped).
Quickstart
- Install with your favorite package manager:
- pnpm :
pnpm add pinia-plugin-persistedstate - npm :
npm i pinia-plugin-persistedstate - yarn :
yarn add pinia-plugin-persistedstat
Add the plugin to pinia:
import { createPinia } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
const pinia = createPinia()
pinia.use(piniaPluginPersistedstate)
Add the persist option to the store you want to be persisted:
import { defineStore } from 'pinia'
export const useStore = defineStore('store', {
state: () => ({
someState: 'hello pinia',
}),
persist: true,
})