@mwjz/pinia-storage
v0.0.3
Published
Persistence state in your pinia 🍍 store!
Downloads
4
Maintainers
Readme
Persistence state in your pinia 🍍 store!
Installation
npm install @mwjz/pinia-storage
Usage
import { PiniaStorage } from '@mwjz/pinia-storage'
// Pass the plugin to your application's pinia plugin
pinia.use(PiniaStorage())
You can then use storage
option in your stores:
defineStore('id', {
state: () => ({ bar: '', baz: 0, foo: null }),
storage: {
local: ['bar'],
session: {
baz: {
read: (baz) => Number(baz)
},
foo: {
write: (foo: object) => JSON.stringify(foo),
read: (foo) => {
try {
if (!foo) return null;
return JSON.parse(foo);
} catch (error) {
return null
}
}
},
}
}
})