遇到vuex
刷新state
就不见,之前都是用插件的。
然后昨天看到这个blog.csdn.net/guzhao593/a…
是用session
保存的,所以记下方向。
//在根页面app.js中的created中写入,这样就可以在每个页面都可以监听得到
//在页面加载时读取sessionStorage里的状态信息
if (sessionStorage.getItem("store")) {
// this.$store.replaceState替换 store 的根状态,仅用状态合并或时光旅行调试。
this.$store.replaceState(Object.assign({}, this.$store.state, JSON.parse(sessionStorage.getItem("store"))))
}
//在页面刷新时将vuex里的信息保存到sessionStorage里
window.addEventListener("beforeunload", () => {
sessionStorage.setItem("store", JSON.stringify(this.$store.state))
})