Persist and rehydrate your Vuex state between page reloads

vuex-persistedstate

Persist and rehydrate your Vuex state between page reloads.

robinvdvleuten/vuex-persistedstate Maintenance has stopped, but a lot of developers are still using vuex-persistedstate , so we try to replace it。

will try to keep the same API to achieve risk-free replacement.


Install

npm install --save vuex-plugin-persistedstate

The UMD build is also available on unpkg:

<script src="https://unpkg.com/vuex-plugin-persistedstate/dist/index.js"></script>

Usage

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

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

Compatible with vuex 3 && vuex 4

Examples

Check out a basic example on CodeSandbox.

Options

export interface Options<State> {
  /**
   * localStorage saved key
   */
  key: string
  /**
   * cached module name
   * Do not pass means cache all
   * pass only the specified cache
   */
  paths: string[]
  /**
   * storage
   */
  storage: Storage
  /**
   * Whether to prefetch data
   */
  fetchBeforeUse: boolean
  /**
   * Default method of prefetching data
   */
  fetchBeforeUseFn: (key: string, storage: Storage) => any
}

License

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

GitHub

View Github