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.
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>
import { createStore } from "vuex";
import createPersistedState from "vuex-plugin-persistedstate";
const store = createStore({
// ...
plugins: [createPersistedState()],
});
Compatible with vuex 3 && vuex 4
Check out a basic example on CodeSandbox.
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
}
The MIT License (MIT). Please see License File for more information.