From 0c9105b54eba376acb23c65643999fcd87d6974a Mon Sep 17 00:00:00 2001 From: XiaoDaiGua-Ray <443547225@qq.com> Date: Fri, 15 Dec 2023 11:23:51 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E6=9B=B4=E6=96=B0router=E5=8C=85?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E5=B0=8F=E7=BB=86=E8=8A=82=EF=BC=8C=E5=92=8C?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/helper/setupHelper.ts | 10 +++++++--- src/router/index.ts | 5 ----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/router/helper/setupHelper.ts b/src/router/helper/setupHelper.ts index a7f49754..d0bf409a 100644 --- a/src/router/helper/setupHelper.ts +++ b/src/router/helper/setupHelper.ts @@ -93,10 +93,14 @@ export const orderRoutes = (routes: AppRouteRecordRaw[]) => { /** * - * 切换路由时, 手动将容器区域回归默认值 + * @param route 路由对象 * - * 由于官方不支持这个方法了, 所以自己手写了一个 - * 如果需要忽略恢复默认位置, 仅需要在 meta 中配置 ignoreAutoResetScroll 属性即可 + * 当路由切换后自动将内容区域滚动到顶部(x、y都会归于 0),如果需要忽略该功能,可以在路由的 meta 中配置 ignoreAutoResetScroll 属性 + * + * @example + * scrollViewToTop({ + * meta: { ignoreAutoResetScroll: true } + * }) // 不会滚动到顶部,维持上一次的滚动位置 */ export const scrollViewToTop = (route: RouteLocationNormalized) => { const { meta } = route diff --git a/src/router/index.ts b/src/router/index.ts index 346b6cca..a9227dd4 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -21,11 +21,6 @@ const createVueRouter = async () => { routes: (await constantRoutes()) as unknown as RouteRecordRaw[], scrollBehavior: (to) => { scrollViewToTop(to) - - return { - top: 0, - left: 0, - } }, }) }