persistia
v1.1.0
Published
Persist Pinia state data in localStorage
Downloads
60
Readme
persistia
Persist Pinia state data in localStorage
Installation
Install with your favourite package manager:
# yarn
yarn add persistia
# pnpm
pnpm add persistia
# npm
npm install persistia
Import and install:
// main.js
import { createPinia } from 'pinia'
import { persistia } from 'persistia'
const pinia = createPinia()
pinia.use(persistia)
Enable the plugin per store:
import { defineStore } from 'pinia'
export const useStore = defineStore('...', {
persist: true,
state: () => ({ ... }),
actions: { ... },
getters: { ... }
})
Alternatively, you can specify which keys in state
to persist:
import { defineStore } from 'pinia'
export const useStore = defineStore('...', {
persist: ['name', 'age'],
state: () => ({
name: 'Jane Doe',
age: 42,
email: '[email protected]',
address: '123 Fake St.'
}),
actions: { ... },
getters: { ... }
})