A Vuex4, Vue3 and Nuxt - ready plugin that saves and rehydrates the state of your application between page reloads
npm install vuex-persisterSmallest and fastest Vuex4, Vue3 and Nuxt - ready plugin that saves and rehydrates the state of your application between page reloads



![license]()
!Build Status


``bash`
npm install --save vuex-persister
or
`bash`
yarn add vuex-persister
js
import VuexPersister from 'vuex-persister'
`$3
`js
// JavaScript
const vuexPersister = new VuexPersister({
// ...your options
})// Typescript
const vuexPersister = new VuexPersister({
// ...your options
})
`$3
`js
// JavaScript
const store = createStore({
state: {/ ... /},
// ...
plugins: [vuexPersister.persist] // integrate the plugin
})// TypeScript
const store = createStore({
state: {/ ... /},
// ...
plugins: [vuexPersister.persist] // integrate the plugin
})
`Nuxt.js
$3
`js
// ~/plugins/vuex-persister.js
import VuexPersister from 'vuex-persister'export default ({ store }) => {
new VuexPersister({
// ...your options
}).persist(store)
}
`$3
`js
// ~nuxt.config.js
export default {
/ ... other options here /
plugins: [{ src: '~/plugins/vuex-persister.js', ssr: false }],
}
`
API
$3
Creates an instance of the plugin while accepting specific options as below:
-
key : The key with which to store the state in the specified storage. Defaults to vuex.
- statesToPersist : The specific states that needs to be persisted. Use dot notation for moduled states e.g. user.name.
Defaults to an empty array and saves all objects in the state instance.
- overwrite : Whether to overwrite the state with the saved state instead of merging the two objects with deepmerge. Defaults to false.
- storage