Skip to content

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

Open
@haizhilin2013

Description

@haizhilin2013
Collaborator

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

Activity

bettermu

bettermu commented on Jun 30, 2019

@bettermu

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

szwShen

szwShen commented on Nov 7, 2019

@szwShen

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

LQY-3777

LQY-3777 commented on Nov 26, 2019

@LQY-3777

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

WenJieLi1998 commented on Apr 19, 2020

@WenJieLi1998

在路由实例中配置
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @haizhilin2013@bettermu@WenJieLi1998@szwShen@LQY-3777

        Issue actions

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