vuejs-storage icon indicating copy to clipboard operation
vuejs-storage copied to clipboard

Define the keys within the modules

Open rderimay opened this issue 7 years ago • 3 comments

This is not a bug. It is a request / question.

Let say you have a standard vuex structure with a few modules

export default new Vuex.Store({
  modules: {
    moduleA,
    moduleB,
},

  plugins: [
    VueJsStorage({
      keys: [
        'moduleA.all'
      ],
      namespace: 'test',
    }),
  ],
})

with moduleA:

const state = {
  all: {},
}

export default {
  state,
  getters,
  mutations,
  actions,
}

This works perfectly, as intended. For me thought, it breaks the modularity of the modules, as the vuex parent has to know about the name of the keys to be persisted with its submodules.

It would be more modular if the sub modules could define their permitted keys themselves.

Is there a way to reach this?

Many thanks!

rderimay avatar May 15 '18 14:05 rderimay

I think it is impossible until Vuex supports plugin for each module. Vuex issue: https://github.com/vuejs/vuex/issues/467

maple3142 avatar May 15 '18 14:05 maple3142

ok, thanks. Bad news :-)

rderimay avatar May 15 '18 15:05 rderimay

This can be done by registering vuejs-storage multiple times, one for each module.

lucianodltec avatar Feb 13 '21 13:02 lucianodltec