Vuex-persistedstate: [question] reset state

Created on 30 Jun 2017  路  7Comments  路  Source: robinvdvleuten/vuex-persistedstate

How do I reset state to how it's defined in my store?
During development, I sometimes change the state object by removing properties.
However, after clearing localStorage/reloading, the removed props + data come up again.
Where does the plugin persist the state? Can I clear it programmatically?

const state     = {
  list: [],
// testField comes up again in localStorage, although removed in vuex state
 //testField: '', 
}
question

Most helpful comment

I'm still having trouble with resetting state. Whenever I change the default state in my vuex file (adding/changing/removing a prop) I need to clear localstorage, close the browser, stop webpack dev server, comment out persisted state in the my vuex store.js and restart everything again. And even then, sometimes the old state still comes back, ignoring my changes to the default vuex state.

What's the procedure to reset local storage to the default state of your vuex file?

All 7 comments

How do you clear the localstorage? Do you do this through the devtools inspector?

ah, my bad. The client connection to the app server was resetting state to old data. When I disconnect server, empty localstorage (devtools) and reload, my localStorage state equals vuex initial state again. So this has nothing to do with vuex-persistedstate. Sorry.

I'm still having trouble with resetting state. Whenever I change the default state in my vuex file (adding/changing/removing a prop) I need to clear localstorage, close the browser, stop webpack dev server, comment out persisted state in the my vuex store.js and restart everything again. And even then, sometimes the old state still comes back, ignoring my changes to the default vuex state.

What's the procedure to reset local storage to the default state of your vuex file?

It seems that vuex-persistedstate is fast enough to get browser localStorage before I remove it on start of the app and then set again after.

I was able to reset Vuex state with simple localStorage.removeItem('vuex-state-name') executed right before new Vuex.Store() with plugin initialization.

@ryaposov that's indeed also an option if you will execute this before creating the Vuex store.

Please see issue #88. You should reset your state by using mutations instead of touching the localStorage instance directly.

Thanks for the tip. I was indeed already using a logout method that loops through all the vuex modules, clearing their states. However during development it's sometimes convenient to clear the store all together with localStorage.removeItem() just before new Vuex.Store() @ryaposov thanks for that!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

irrg picture irrg  路  6Comments

umardraz picture umardraz  路  3Comments

gimyboya picture gimyboya  路  3Comments

kylebradshaw picture kylebradshaw  路  5Comments

rodneyrehm picture rodneyrehm  路  3Comments