Does not work with modules in the initiator
Opened this issue · 3 comments
I stumbled upon your repo and used it as a guide to get started with a vue app in conjunction with a few others. Thanks for publishing.
After getting over the 1st few learning blocks of vuejs the natural step (for me) was to persist the vuex state and "re-hydrate" (developers come up with the most ridiculous use of English words, as this use case has nothing to with water) the store with the previously saved state on new page load.
https://www.npmjs.com/package/vuex-persist
After searching i found this package which requires that the modules "should be registered in the Vuex constructor. When using store.registerModule you risk the (restored) persisted state being overwritten with the default state defined in the module itself."
As I had setup my modules in the method from this repo i was not injecting them into the store, but when i did it was throwing errors saying it could not find getters: https://stackoverflow.com/questions/55843052/vuex-not-loading-module-decorated-with-vuex-module-decorators
Long story short, I think the line export const AuthenticationModule = getModule(Authentication);
is not enough for the new Vuex.Store
and instead the module should be exported from the index.ts
instead: https://stackoverflow.com/questions/55843052/vuex-not-loading-module-decorated-with-vuex-module-decorators#answer-55843970
I did not get a reply from the author of the decorator package nor an answer on stackoverflow, nor am i seasoned vuejs developer yet... but implement the modules in the way i answered in the SO post is working perfectly now with the vuex.persist and i can also write my modules in the same DRY fashion from your admin repo.
Would love to know your thoughts.
Thank you for your question, you can also use this.$store
。Just like normal use of vuex
。
Yea, this does not solve the vuex-persist issue (which actually comes from the same devleoper as the vuex-module-decorators, https://github.com/championswimmer/
If you want to use getters
demo:https://github.com/Vexth/vue3admin/blob/master/src/store/modules/app.ts