[Vuejs]-Position scrollY no changed when route change – vuejs

0👍

Default case in VueJs is to keep Yscroll position when changing page.

You can change your vue-router setting to scroll to the top of your page each time you changing it;

There is a StackOverflow here: https://stackoverflow.com/a/50901500/12592396

And a more compete answer here:
https://stackoverflow.com/a/52111880/12592396

The short anwser is to define scrollBehavior on your Router:

export default new Router({
    mode: ...,
    routes: [
        ...
    ],
    scrollBehavior (to, from, savedPosition) {
        return { x: 0, y: 0 }
    }
})

Leave a comment