在app.vue 的created钩子里加下面代码
export default {
name: 'app',
components: {},
created() {
if (sessionStorage.getItem("vuexState") ) {
this.$store.replaceState(Object.assign({}, this.$store.state,JSON.parse(sessionStorage.getItem("vuexState"))))
console.log('取回了vuex数据asdadasdasdas 数据为+'+this.$store.state)
}
window.addEventListener('beforeunload',()=>{
sessionStorage.setItem("vuexState",JSON.stringify(this.$store.state))
console.log('刷新前保存了vuex 值为'+JSON.stringify(sessionStorage.getItem('vuexState')))
})
}
};
`