Vue switch route page back to the top

MMP, found some on the Internet, tried everything, but at the beginning, it was not good. I didn't know what was behind it, but it was OK

First

stay main.js Add in

 //Jump back to top router.afterEach((to,from,next) => { window.scrollTo(0,0); })

Second

Or the lower one is similar to the upper one

 router.beforeEach(function(to, from, next) { window.scrollTo(0, 0) next() }) })

Third

When configuring routed index.js Add in

This advance will return to the top, and the retreat will not move

This is more humanistic

 ////////Put it inside export default new Router({ scrollBehavior (to, from, savedPosition) { if (savedPosition) { return savedPosition } else { return { x: 0, y: 0 } } } })

comment

Post reply

Your email address will not be disclosed. Required items have been used * tagging




Enter Captcha Here :