Commit 21be1efe authored by lipengcheng 's avatar lipengcheng

feat: 路由增加scrollBehavior属性 保留页面滚动位置

parent 7bd7c3c3
......@@ -28,7 +28,17 @@ routes.push(wildcardRoutes)
const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes
routes,
scrollBehavior(to, from, savedPosition) {
if (savedPosition) {
return savedPosition
} else {
if (from.meta.keepAlive) {
from.meta.savedPosition = document.body.scrollTop
}
return { x: 0, y: to.meta.savedPosition || 0 }
}
}
})
export default router
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment