如何在注销时清除所有 Vuex 4 状态?

How to clear all Vuex 4 states on logout?

有没有办法清除所有 Vuex 4 状态?

来自 store.ts 的代码:

export const store = createStore<Record<string, any>>({
  strict: process.env.NODE_ENV === 'development',
  plugins: [
    createPersistedState({
      storage: {
        getItem: k => secureLS.get(k),
        setItem: (k, v) => secureLS.set(k, v),
        removeItem: k => secureLS.remove(k),
      },
    }),
  ],
  mutations: {},
  actions: {},
  modules: {
    user,
  },
})

vuex-extensions 现在支持 Vuex 4。

正在创建商店:

import { Store } from 'vuex'
import { createStore } from 'vuex-extensions'

export default createStore(Store, {...})

清除存储状态:

// Composition API
useStore().reset()

// Option API
this.$store.reset()