weex-vuex-storage
依据Vuex的module来存储数据到storage
install
npm install weex-vuex-storage -S
use
加载vuex插件
store.js
;const plugins = ;plugins; Vuex
给action添加修饰器,调用action时存储当前module的state到storage,同时给需要存储的state属性添加到黑白名单,不能在同一个module中同时使用shouldWrite
和forbidWrite
module.js
;const module = ... state: @shouldWrite someState: {} actions: @setState { }
也可以手动获取storage中的数据
view.vue
; methods: // module A storage data { }
获取storage快照数据,导入快照数据至storage并同步更新module的state
view.vue
; methods: { // 获取快照数据 } { // 导入快照数据,并更新对应state // 快照数据可由getModuleMap导出,key由createStatePlugin时填写 }