src/App.vue
@@ -17,7 +17,26 @@ return {}; }, created() { }, mounted () { window.addEventListener('beforeunload', e => { sessionStorage.setItem('beforeunload', 1); }); // 监听页面刷新 if (sessionStorage.getItem('beforeunload') == 1) { let name = sessionStorage.getItem("routerName"); if (name) { this.$nextTick(function () { this.$router.push({ path: name }); //如果sessionStorage存在路由,去缓存的路由 }) } else { this.$nextTick(function () { this.$router.push({ path: '/' }); //不存在存储,去主页 }) } } }, beforeDestroy() { }, };