The stored browser values (localStorage, cookie, etc.) changes can be synced with Vuex state. For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
You can optionally set a custom Vuex module name:
1 2 3 4 5
How does it work?
It adds a
warehousemodule into the Vuex store, which contains the state representing the last change made to the browser store (localStorage, cookie, etc.):
1 2 3 4
store.state.warehouse.action // action performed (set, remove, clearAll) store.state.warehouse.key // key affected store.state.warehouse.value // sent value store.state.warehouse.oldValue // last value before performing the action
When an action is performed with vue-warehouse, the Vuex store's state is updated.
store.state.warehouseis immutable, because it is derived state from the changes sent to vue-warehouse, which is the source of truth. You should not attempt to update the browser store (localStorage, cookie, etc.) by mutating the warehouse object. Instead, just call