Skip to content

Instantly share code, notes, and snippets.

@brospars
Created September 18, 2020 11:54
Show Gist options
  • Save brospars/0d41420bf65a6ab9f17545edf81bc6de to your computer and use it in GitHub Desktop.
Save brospars/0d41420bf65a6ab9f17545edf81bc6de to your computer and use it in GitHub Desktop.
Reset Vuex state store

Reseting Vuex module to its original state could be tideous if you have to manually reset all values. So instead you could use a function to retrieve the default state.

const getDefaultState = () => {
  return {
    id: '',
    authors: []
  }
}

const state = getDefaultState()

const mutations = {
  resetEditor(state) {
    Object.assign(state, getDefaultState())
  }
}

const actions = {
  resetEditor({ commit }) {
    commit('resetEditor')
  }
}

export default {
  state,
  mutations,
  actions
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment