vue3路由切换将页面自动滚动到顶部

2,716 阅读1分钟

在进行路由跳转时,页面没有滚动到顶部的解决方案

route/index.js

const router = createRouter({
  history: createWebHashHistory(),
  routes,
  // 每次切换路由页面滚动到顶部
  scrollBehavior () {
    return { top: 0 }
  }
})

参考Vue Router