<template> <div class="app"> <router-view></router-view> </div> </template> <script> export default { data() { return {}; }, created() { this.readVueXData(); }, methods: { // 解决刷新store初始化问题 readVueXData() { window.addEventListener("beforeunload", () => { sessionStorage.setItem("store", JSON.stringify(this.$store.state)); }); if (sessionStorage.getItem("store")) { this.$store.replaceState( Object.assign( {}, this.$store.state, JSON.parse(sessionStorage.getItem("store")) ) ); sessionStorage.removeItem("store"); } }, }, }; </script> <style lang="less" scoped> .app { width: 100%; min-width: 1400px; min-height: 100%; background-color: #f0f2f5; display: flex; } </style>