提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
–
App.vue页面也引入
<script>
export default {
name: 'App',
created() {
if (window.localStorage.getItem('store')) {
this.$store.replaceState(
Object.assign(
{},
this.$store.state,
JSON.parse(window.localStorage.getItem('store'))
)
)
// 刷新重置loading状态
// this.$store.state.permission.loading = false
}
window.addEventListener('beforeunload', () => {
window.localStorage.setItem('store', JSON.stringify(this.$store.state))
})
},
//两个生命周期解决ios登录刷新登出问题
beforeMount() {
window.addEventListener('pagehide', () => {
sessionStorage.setItem('store', JSON.stringify(this.$store.state));
});
},
mounted() {
const storeData = sessionStorage.getItem('store');
if (storeData) {
this.$store.replaceState(JSON.parse(storeData));
}
}
}
</script>