vuex刷新数据清空的问题
可以写在APP.vue的created里
// vuex状态管理,在网页刷新数据被清空的解决方法。
if (sessionStorage.getItem('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))
})
}