Vuex persistedstate

When you want your app’s state to persist across multiple pages loads etc. you can use vuex. In a naive way add a function call in each mutation to save the current state of the app to local Storage. You know this is not a better way therefore we use the already available package- vuex-persistedstate. It automatically syncs your store with local Storage or other storage methods. Vue.js v2.0.0+ and Vuex v2.0.0+ are the requirements you need to install vuex persistedstate.

Install it using npm.


npm install --save vuex-persistedstate


To use the vuex-persistedstate follow the below syntax.


import createPersistedState from "vuex-persistedstate";

 

const store = new Vuex.Store({

  // ...

  plugins: [createPersistedState()],

});