在created、mounted 都行啊。
window.addEventListener('beforeunload', e => {
localStorage.setItem("store",JSON.stringify(this.$store.state))
});