Clear or reset Store State to initial state on Logout!

is it possible to reset all states of variables to initial state on logout with one command?

this for me didn’t work

      $f7.views.main.router.navigate('/', {
        reloadAll: true,
        ignoreCache: true,
        clearPreviousHistory: true

is there a way to initialise the store states without having to create a method to set all
states to null as below? the reason I have a bunch of states and resetting them manually does not make sense if there is a simple way in one line to do it!

I do not want to do this for all my states on logout, see below…

      state.stores = null;
.... /// (long list)

any tip?

  state: { key1: 'value1', key2: 'value2' },
  actions: {
    clear: ({ state }) => Object.keys(state).forEach(i => state[i] = null)

Big thanks for the lines of code! I will test it now! some states are not defined as null but have initial values! so I think I need some sort of modification above!


const defaults = { key: null, arr: [], obj: {} };
export default createStore({
  state: defaults,
  actions: {
    clear: ({ state }) => Object.entries(defaults)
      .forEach(([k,v]) => state[k] = v)
1 Like

great thanks for the tips!