[Solved] How do I reset a vuex store in Quasar?
rconstantine last edited by rconstantine
I’d like to reset my store when a user logs out. No data should be saved from one session to another.
The following post speaks somewhat to what I’m trying to do, but I think vuex is organized a bit differently in Quasar, so I’m not sure how to apply it. (https://github.com/vuejs/vuex/issues/1118)
In the file tree shown here: https://quasar-framework.org/guide/app-vuex-store.html, can I just add action and mutation files to the same level as index.js?
Or are you guys resetting your application some other way, particularly at logout?
Also, what does “if we want some HMR magic for it” mean?
Thanks - Ryan
Quasar usage of vuex is not different. It’s all basic vuejs functionality and resetting the store could be done by any action/mutation clearing/nulling your variables.
Any specific problems doing that?
panstromek last edited by
if we want some HMR magic for itis related to hot reload - if you want the store to reload only a single module on changes during development instead of trigger rebuild.
And yes, you can organize the store however you want - put everything in index.js, or on the same level… it’s up to you. Quasar scaffolds very granular setup at start, but you can definitely reorganize it for your needs. I tend to have just per-file modules, because they are usually pretty small in my projects. In the end store is just a bunch of JS objects and functions that you put inside the Store constructor. There is no restriction on how you organize them.
You can reset the store with some mutation nulling all variables like Max said. I often use dynamic modules and just register one on login and unregister it on logout. That way I can just throw out all the data easily.
metalsadman last edited by metalsadman
@rconstantine when you refresh page
window.location.reload()i think vuex will be reset, or you can use https://github.com/robinvdvleuten/vuex-persistedstate, then clear the LocalStorage/SessionStorage on logout ie.
rconstantine last edited by
Thanks for the suggestions. I did end up just making reset actions/mutations for each store module. Seems to work.