A Vuex plugin to persist the store. (Fully Typescript enabled)
Vuex-persist is a Vuex plugin that allows you to save your app’s state to a persisted storage like Cookies or localStorage. It enables automatic saving of store on mutation, choosing which mutations trigger store save, and supports saving partial store using a reducer function. The plugin also features compatibility with VueJS v2.0 and above, and Vuex v2.1 and above.
To install vuex-persist, you can use Vue CLI Build Setup with Webpack or any bundler. If you need to transpile for target es5, follow the steps below:
Install the module using npm or yarn.
npm install vuex-persist --save
Import the module in your project.
import VuexPersistence from 'vuex-persist';
Use VuexPersistence as a plugin in your Vue app.
const vuexLocal = new VuexPersistence({
storage: window.localStorage,
});
Vue.use(Vuex);
const store = new Vuex.Store({...your modules});
vuexLocal.plugin(store);
Vuex-persist is a useful Vuex plugin that simplifies the persistent storage of your app’s state. With features like automatic state restoration, partial store saving, and support for Promise based stores, it provides a convenient solution for managing state persistence in VueJS applications. Its compatibility with VueJS and Vuex versions makes it a versatile choice for developers looking to implement efficient state management in their projects.