From 7302dadaba783c1346b47b40f533280d6c3e4fa2 Mon Sep 17 00:00:00 2001 From: liupengpeng <276665548@qq.com> Date: 星期五, 10 二月 2023 15:34:31 +0800 Subject: [PATCH] 页面刷新还在本页面 --- src/App.vue | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-) diff --git a/src/App.vue b/src/App.vue index 1f9c81a..cb0be87 100644 --- a/src/App.vue +++ b/src/App.vue @@ -18,6 +18,24 @@ }, 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() { }, }; </script> -- Gitblit v1.9.3