Need help with vuex-persistedstate?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

5.5K Stars 331 Forks MIT License 292 Commits 21 Opened issues


💾 Persist and rehydrate your Vuex state between page reloads.

Services available


Need anything else?

Contributors list


Persist and rehydrate your Vuex state between page reloads.

Build Status NPM version NPM downloads Prettier MIT license

PRs Welcome Code Of Conduct

Sponsored by The Webstronauts


npm install --save vuex-persistedstate

The UMD build is also available on unpkg:

You can find the library on



import { createStore } from "vuex";
import createPersistedState from "vuex-persistedstate";

const store = createStore({ // ... plugins: [createPersistedState()], });

For usage with for Vuex 3 and Vue 2, please see 3.x.x branch.


Check out a basic example on CodeSandbox.

Edit vuex-persistedstate

Or configured to use with js-cookie.

Edit vuex-persistedstate with js-cookie

Or configured to use with secure-ls

Edit vuex-persistedstate with secure-ls (encrypted data)

Example with Vuex modules

New plugin instances can be created in separate files, but must be imported and added to plugins object in the main Vuex file.

/* module.js */
export const dataStore = {
  state: {
    data: []

/* store.js */ import { dataStore } from './module'

const dataState = createPersistedState({ paths: ['data'] })

export new Vuex.Store({ modules: { dataStore }, plugins: [dataState] })

Example with Nuxt.js

It is possible to use vuex-persistedstate with Nuxt.js. It must be included as a NuxtJS plugin:

With local storage (client-side only)

// nuxt.config.js

... /*

// ~/plugins/persistedState.client.js

import createPersistedState from 'vuex-persistedstate'

export default ({store}) => { createPersistedState({ key: 'yourkey', paths: [...] ... })(store) }

Using cookies (universal client + server-side)



npm install --save cookie js-cookie
yarn add cookie js-cookie
// nuxt.config.js
plugins: [{ src: '~/plugins/persistedState.js'}]
// ~/plugins/persistedState.js

import createPersistedState from 'vuex-persistedstate'; import * as Cookies from 'js-cookie'; import cookie from 'cookie';

export default ({ store, req }) => { createPersistedState({ paths: [...], storage: { getItem: (key) => { // See if (process.server) { const parsedCookies = cookie.parse(req.headers.cookie); return parsedCookies[key]; } else { return Cookies.get(key); } }, // Please see, on how to handle JSON. setItem: (key, value) => Cookies.set(key, value, { expires: 365, secure: false }), removeItem: key => Cookies.remove(key) } })(store); };



Creates a new instance of the plugin with the given options. The following options can be provided to configure the plugin for your specific needs:

  • key 
    : The key to store the persisted state under. Defaults to
  • paths 
    : An array of any paths to partially persist the state. If no paths are given, the complete state is persisted. If an empty array is given, no state is persisted. Paths must be specified using dot notation. If using modules, include the module name. eg: "auth.user" Defaults to
  • reducer 
    : A function that will be called to reduce the state to persist based on the given paths. Defaults to include the values.
  • subscriber 
    : A function called to setup mutation subscription. Defaults to
    store => handler => store.subscribe(handler)
  • storage 
    : Instead of (or in combination with)
    . Defaults to localStorage.
  • getState 
    : A function that will be called to rehydrate a previously persisted state. Defaults to using
  • setState 
    : A function that will be called to persist the given state. Defaults to using
  • filter 
    : A function that will be called to filter any mutations which will trigger
    on storage eventually. Defaults to
    () => true
  • overwrite 
    : When rehydrating, whether to overwrite the existing state with the output from
    directly, instead of merging the two objects with
    . Defaults to
  • arrayMerger 
    : A function for merging arrays when rehydrating state. Defaults to
    function (store, saved) { return saved }
    (saved state replaces supplied state).
  • rehydrated 
    : A function that will be called when the rehydration is finished. Useful when you are using Nuxt.js, which the rehydration of the persisted state happens asynchronously. Defaults to
    store => {}
  • fetchBeforeUse 
    : A boolean indicating if the state should be fetched from storage before the plugin is used. Defaults to
  • assertStorage 
    : An overridable function to ensure storage is available, fired on plugins's initialization. Default one is performing a Write-Delete operation on the given Storage instance. Note, default behaviour could throw an error (like
    DOMException: QuotaExceededError

Customize Storage

If it's not ideal to have the state of the Vuex store inside localstorage. One can easily implement the functionality to use cookies for that (or any other you can think of);

Edit vuex-persistedstate with js-cookie

import { Store } from "vuex";
import createPersistedState from "vuex-persistedstate";
import * as Cookies from "js-cookie";

const store = new Store({ // ... plugins: [ createPersistedState({ storage: { getItem: (key) => Cookies.get(key), // Please see, on how to handle JSON. setItem: (key, value) => Cookies.set(key, value, { expires: 3, secure: true }), removeItem: (key) => Cookies.remove(key), }, }), ], });

In fact, any object following the Storage protocol (getItem, setItem, removeItem, etc) could be passed:

createPersistedState({ storage: window.sessionStorage });

This is especially useful when you are using this plugin in combination with server-side rendering, where one could pass an instance of dom-storage.

🔐Obfuscate Local Storage

If you need to use Local Storage (or you want to) but want to prevent attackers from easily inspecting the stored data, you can obfuscate it.

Important ⚠️ Obfuscating the Vuex store means to prevent attackers from easily gaining access to the data. This is not a secure way of storing sensitive data (like passwords, personal information, etc.), and always needs to be used in conjunction with some other authentication method of keeping the data (such as Firebase or your own server).

Edit vuex-persistedstate with secure-ls (obfuscated data)

import { Store } from "vuex";
import createPersistedState from "vuex-persistedstate";
import SecureLS from "secure-ls";
var ls = new SecureLS({ isCompression: false });


const store = new Store({ // ... plugins: [ createPersistedState({ storage: { getItem: (key) => ls.get(key), setItem: (key, value) => ls.set(key, value), removeItem: (key) => ls.remove(key), }, }), ], });

⚠️ LocalForage ⚠️

As it maybe seems at first sight, it's not possible to pass a LocalForage instance as

property. This is due the fact that all getters and setters must be synchronous and LocalForage's methods are asynchronous.


Please see CHANGELOG for more information on what has changed recently.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Robin van der Vleuten

💻 📖 🚇 ⚠️


💻 📖

Boris Graeff


Cícero Pablo


Gurpreet Atwal


Jakub Koralewski


Jankees van Woezik


Jofferson Ramirez Tiquez


Jordan Deprez


Juan Villegas


Jürg Rast


Kartashov Alexey


Leonard Pauli

💻 📖

Nelson Liu

💻 📖 ⚠️


💻 ⚠️

Quentin Dreyer


Raphael Saunier


Rodney Rehm

💻 ⚠️

Ryan Wang

💻 📖 ⚠️

Sébastien Chopin






Paul Melero

📖 💻 ⚠️

Guillaume da Silva


Jonathan Santerre


Fábio Santos






David Bond


Freek van Rijt


Ilyes Hermellin


Peter Siska


Dmitry Filippov


Thomas Meitz

📖 ⚠️

Neeron Bhatta




This project follows the all-contributors specification. Contributions of any kind welcome!


The MIT License (MIT). Please see License File for more information.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.