1.0.0 • Published 5 years ago

vuex-module-storage v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

vuex-module-storage

依据Vuex的module来存储数据到storage

install

npm install vuex-module-storage -S

use

加载vuex插件

store.js

import {createStatePlugin} from 'vuex-module-storage';
const plugins = [];
plugins.push(createStatePlugin({
  key: 'rootKey', // 根节点的key
  intercept: function(init) {
    router.beforeEach((from, to, next) => {
      init.then(next);
    });
  }
}));
export default new Vuex.Store({
  ...
  plugins,
})

给需要存储的state属性添加到白名单,在state.someState改变时,就能保存到storage

module.js

import {shouldWrite} from 'vuex-module-storage';
const module = {
  ...
  state: {
    @shouldWrite
    someState: {}
  },
}