Vexth / vue3admin

vue-cli3.xx+typescript+element-ui后台管理,迁移到vue-admin-ts
4 stars 4 forks source link

Does not work with modules in the initiator #1

Open j-d-carmichael opened 5 years ago

j-d-carmichael commented 5 years ago

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.

Vexth commented 5 years ago

Thank you for your question, you can also use this.$store。Just like normal use of vuex

j-d-carmichael commented 5 years ago

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/

Vexth commented 5 years ago

If you want to use getters demo:https://github.com/Vexth/vue3admin/blob/master/src/store/modules/app.ts