From 6b41f3bb64ee0a29c03ee8cf7f2b29a133a56da1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=AE=E5=8F=AE=E5=BD=93?= <604054726@qq.com> Date: Tue, 19 Sep 2023 10:33:52 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/App.vue b/src/App.vue index f5326d59..e834d2d6 100644 --- a/src/App.vue +++ b/src/App.vue @@ -7,9 +7,6 @@ import store from './store' const { global: globalTheme } = useTheme() globalTheme.name.value = localStorage.getItem('theme') || 'light' -// 路由 -const route = useRoute() - // 提示框 const $toast = useToast() From 2a41e8a7262d2841bed53421ac0b0b1ddc0e301c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=AE=E5=8F=AE=E5=BD=93?= <604054726@qq.com> Date: Tue, 19 Sep 2023 10:34:49 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E7=9A=84=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.ts | 16 ---------------- src/router/index.ts | 7 +++++-- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/src/main.ts b/src/main.ts index 03358e6d..38743456 100644 --- a/src/main.ts +++ b/src/main.ts @@ -30,9 +30,6 @@ app.use(vuetify) }) .use(VuetifyUseDialog).mount('#app') -// 记录和恢复滚动位置 -const scrollPositions: { [key: string]: number } = {} // 用于存储每个路由的滚动位置 - // 路由导航守卫 router.beforeEach((to, from, next) => { const isAuthenticated = store.state.auth.token !== null @@ -41,24 +38,11 @@ router.beforeEach((to, from, next) => { next('/login') } else { - // 只有 meta 中 keepAlive 为 true 的情况下才记录滚动位置 - if (from.meta.keepAlive) - scrollPositions[from.fullPath] = window.scrollY - startNProgress() next() } }) router.afterEach((to) => { - // 只有 meta 中 keepAlive 为 true 的情况下才恢复滚动位置 - if (to.meta.keepAlive) { - const savedPosition = scrollPositions[to.fullPath] - if (savedPosition !== undefined) { - setTimeout(() => { - window.scrollTo(0, savedPosition) - }, 0) - } - } doneNProgress() }) diff --git a/src/router/index.ts b/src/router/index.ts index 6882cfe4..bde7aa72 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -2,8 +2,11 @@ import { createRouter, createWebHistory } from 'vue-router' const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), - scrollBehavior() { - // 始终滚动到顶部 + scrollBehavior(to, from, savedPosition) { + // 如果页面有缓存那么恢复其位置, 否则始终滚动到顶部 + if (to.meta.keepAlive && savedPosition) + return savedPosition + console.log('top: 0') return { top: 0 } }, routes: [ From 4d778e9ca9944872716386f2f4a4bace99a5e047 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=AE=E5=8F=AE=E5=BD=93?= <604054726@qq.com> Date: Tue, 19 Sep 2023 10:36:59 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E7=9A=84=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/router/index.ts b/src/router/index.ts index bde7aa72..2a1402e7 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -6,7 +6,7 @@ const router = createRouter({ // 如果页面有缓存那么恢复其位置, 否则始终滚动到顶部 if (to.meta.keepAlive && savedPosition) return savedPosition - console.log('top: 0') + // console.log('top: 0') return { top: 0 } }, routes: [ From b1635b071544234d1616bcc8da7278d663551ab0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=AE=E5=8F=AE=E5=BD=93?= <604054726@qq.com> Date: Tue, 19 Sep 2023 10:42:46 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8DIOS14=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E9=A1=B5=E6=98=BE=E7=A4=BAbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/login.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/login.vue b/src/pages/login.vue index 0421e999..5777649f 100644 --- a/src/pages/login.vue +++ b/src/pages/login.vue @@ -130,7 +130,7 @@ onMounted(() => {