How to clear state in vuex store?

后端 未结 12 1316
既然无缘
既然无缘 2020-12-23 12:21

My state in vuex store is huge.

Is there a way to reset all the data in state in one go, instead of manually setting everything to null?

12条回答
  •  悲哀的现实
    2020-12-23 13:13

    You could take it easy by tiny package: vuex-extensions

    Check out the example on CodeSandbox.

    Creating Vuex.Store

    import Vuex from 'vuex'
    import { createStore } from 'vuex-extensions'
    
    export default createStore(Vuex.Store, {
      plugins: []
      modules: {}
    })
    
    Store resets to initial State
    // Vue Component
    this.$store.reset()
    
    // Vuex action
    modules: {
      sub: {
        actions: {
          logout() {
            this.reset()
          }
        }
      }
    }
    

提交回复
热议问题