vuex刷新數據清空的問題 - 穩住別慌 - 博客園 (cnblogs.com)
//可以寫在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))
})
}
