【vue】vuex持久化插件vuex-persistedstate:
warning:
这篇文章距离上次修改已过184天,其中的内容可能已经有所变动。
import createPersistedState from "vuex-persistedstate";
const store = new Vuex.Store({
// ...state, mutations, actions, and getters...
plugins: [createPersistedState({
storage: window.sessionStorage, // 或者 localStorage
})]
});
这段代码演示了如何在Vuex中使用vuex-persistedstate
插件来持久化状态。在这个例子中,状态被保存在了浏览器的sessionStorage
中,但你也可以选择保存在localStorage
中,localStorage
会在浏览器关闭后依然保存数据,而sessionStorage
则在浏览器关闭后清除数据。
评论已关闭