All Projects → G-Veigar → vue-vuex-persist

G-Veigar / vue-vuex-persist

Licence: other
vuex持久化插件

Programming Languages

javascript
184084 projects - #8 most used programming language
Vue
7211 projects
HTML
75241 projects

Projects that are alternatives of or similar to vue-vuex-persist

mst-persist
Persist and hydrate MobX-state-tree stores (in < 100 LoC)
Stars: ✭ 75 (+368.75%)
Mutual labels:  persistence, state, persist
Hydrated bloc
An extension to the bloc state management library which automatically persists and restores bloc states.
Stars: ✭ 181 (+1031.25%)
Mutual labels:  persistence, state
Rebus.SqlServer
🚌 Microsoft SQL Server transport and persistence for Rebus
Stars: ✭ 35 (+118.75%)
Mutual labels:  persistence
vue-auto-storage
🍻 An automatic storage plugin for Vue2, persist the data with localStorage.
Stars: ✭ 84 (+425%)
Mutual labels:  persistence
restate
A redux fractal state library 🕷
Stars: ✭ 55 (+243.75%)
Mutual labels:  state
Persistence
Plugin para almacenar datos de forma persistente en Godot Engine 3
Stars: ✭ 20 (+25%)
Mutual labels:  persistence
vuex-but-for-react
A state management library for React, heavily inspired by vuex
Stars: ✭ 96 (+500%)
Mutual labels:  state
linper
Linux Persistence Toolkit
Stars: ✭ 20 (+25%)
Mutual labels:  persistence
PageStatusTransformer
A low invasive state management on Android
Stars: ✭ 12 (-25%)
Mutual labels:  state
lovelace-battery-entity-row
Show battery states or attributes with dynamic icon on entity rows in Home Assistant's Lovelace UI
Stars: ✭ 49 (+206.25%)
Mutual labels:  state
particule
Fine-grained atomic React state management library
Stars: ✭ 31 (+93.75%)
Mutual labels:  state
redux-ui-state
UI state management for Redux applications
Stars: ✭ 16 (+0%)
Mutual labels:  state
react-context-io
Share state with ease.
Stars: ✭ 22 (+37.5%)
Mutual labels:  state
immerx-state
Reactive, fractal and no-nonsense state management with Immer
Stars: ✭ 19 (+18.75%)
Mutual labels:  state
concave
🧐 Lens-like state management (for React).
Stars: ✭ 13 (-18.75%)
Mutual labels:  state
reactive state
An easy to understand reactive state management solution for Flutter.
Stars: ✭ 19 (+18.75%)
Mutual labels:  state
android-room-example
Android Kotlin app showcasing the Room persistence library
Stars: ✭ 45 (+181.25%)
Mutual labels:  persistence
jedisdb
redis like key-value state management solution for React
Stars: ✭ 13 (-18.75%)
Mutual labels:  state
riduce
Get rid of your reducer boilerplate! Zero hassle state management that's typed, flexible and scalable.
Stars: ✭ 14 (-12.5%)
Mutual labels:  state
RxReduxK
Micro-framework for Redux implemented in Kotlin
Stars: ✭ 65 (+306.25%)
Mutual labels:  state

vue-vuex-persist

vuex持久化插件, Persist Vuex state by Web Storage

基于beforeunload事件,而不是vuex插件,比传统持久化方案效率更高。

Installation

npm install vue-vuex-persist

Usage

第一步:注册vue插件

import Vue from 'vue';
// vuex store
import store from './store';
import vueVuexPersist from 'vue-vuex-persist';

Vue.use(vueVuexPersist, store, [options]);

第二步:混合state, 并实例化Store对象

import vueVuexPersist from 'vue-vuex-persist';

// 默认state的定义
const state = {
  // state
};

// 调用vueVuexPersist.init(state),将缓存的state属性,覆盖掉默认state属性, 得到一个混合后的state
const hybridState = vueVuexPersist.init(state);

export default new Vuex.Store({
  state: hybridState,
  mutations: {
    // mutations
  },
  actions: {
    // actions
  },
})

API

options参数可选,当没有传入options参数时候,默认会将全部state缓存,生命周期为session,即使用sessionStorage存储。

// persist all state
Vue.use(vueVuexPersist, store);

options为数组时,会将数组中的每一项缓存,生命周期为session。

Vue.use(vueVuexPersist, store, ['state1', 'state2']);

options也可以为对象,对象包括session,local属性,分别代表了state的缓存生命周期

Vue.use(vueVuexPersist, store, {
  session: ['state1', 'state2'],
  local: ['state3', 'state4']
});

License

MIT

Copyright (c) 2018-present, gaoge

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].