Skip to content

[vue] 切换到新路由时,页面要滚动到顶部或保持原先的滚动位置怎么做呢? #381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
haizhilin2013 opened this issue Jun 20, 2019 · 4 comments
Labels
vue vue

Comments

@haizhilin2013
Copy link
Collaborator

[vue] 切换到新路由时,页面要滚动到顶部或保持原先的滚动位置怎么做呢?

@haizhilin2013 haizhilin2013 added the vue vue label Jun 20, 2019
@bettermu
Copy link

滚动到顶部:在new Router()的时候,配置
scrollBehavior(to, from, savedPosition) {
return { x: 0, y: 0 }
}

@szwShen
Copy link

szwShen commented Nov 7, 2019

通过router 的meta来记录需要保存滚动条的位置,在new VueRouter()时调用scrollBehavior(to, from, savedPosition) {return { x: 0, y: 0 }}的方法

@LQY-3777
Copy link

ickt-5:
vue-router 页面切换后保持在页面顶部而不是保持原先的滚动位置的办法:
https://www.cnblogs.com/kugeliu/p/7172042.html
vue2.0路由切换后页面跳转后新页面滚动位置不变BUG(滚动条回到顶部的位置):
https://blog.csdn.net/ZHIYUANfL/article/details/79241655
返回到上次滚动位置:
https://blog.csdn.net/yan263364/article/details/84402595

@WenJieLi1998
Copy link

在路由实例中配置
scrollBehavior(ro,form,savedPosition){
//滚动到顶部
return {x:0,y:0}
//保持原先的滚动位置
return {selector:falsy}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vue vue
Projects
None yet
Development

No branches or pull requests

5 participants