pinia-persist
v0.1.0
Published
Persist and rehydrate your Pinia state between page reloads
Downloads
151
Maintainers
Readme
pinia-persist
This package works for Vue 2 & 3 by the power of Vue Demi!
Getting Started
Installation
NPM
$ npm i pinia-persist # yarn add pinia-persist
CDN
<script src="https://unpkg.com/pinia-persist"></script>
Usage
import { ref } from 'vue' // import { ref } from '@vue/composition-api'
import { createPinia, defineStore } from 'pinia'
import { createPersistPlugin } from 'pinia-persist'
const pinia = createPinia()
pinia.use(createPersistPlugin())
const useCounterStore = defineStore(
'counter-store',
() => {
return {
count: ref(0),
}
},
{ persist: { storage: window.localStorage } },
)
// const counterStore = defineStore('counter-store', {
// state() {
// return { count: 0 }
// },
// persist: { storage: window.localStorage },
// })
const counterStore = useCounterStore()
counterStore.count++ // fires window.localStorage.setItem('counter-store', JSON.stringify({ count: 0 }))
Contributing
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
Versioning
This project use SemVer for versioning. For the versions available, see the tags on this repository.
License
This project is licensed under the MIT License - see the LICENSE file for details