In store folder, create index.js file
const getDefaultState = () => { return { items: [], status: 'empty' } } // initial state const state = getDefaultState() const mutations = { RESET_STATE(state) { Object.assign(state, getDefaultState()) } } </span> const actions = { resetState ({ commit }) { commit('RESET_STATE') }, } export default { state, getters: {}, actions, mutations }
You can now reset the store wherever you want, for exemple on logout with:
this.$store.dispatch('resetState')
Comments
Write comments