The vue2.0-vue-router scroll bar returns to the top

header is fixed. Click the left navigation bar to switch the page so that the scroll bar on the right page is at the top

            
Mar.22,2021

just encountered the same problem
wrote a global function

Vue.prototype.upToTop = function() {
    let dom = document.getElementById('main-content');
    dom.scrollTop = 0;
}

main-content is the tag id for the body of my page
I call this.upToTop (); every time the page data is loaded


Click on the left and right side of the page should be on it. So if there is a scroll bar, it should also be at the top?


scrollBehavior (to, from, savedPosition) {/ / scroll to the top when switching routes

return { x: 0, y: 0 }

},
is added to the routing js


ide/advanced/scroll-behavior.html-sharp%E5%BC%82%E6%AD%A5%E6%BB%9A%E5%8A%A8" rel=" nofollow noreferrer "> https://router.vuejs.org/zh/g.

see if it's what you want.

Menu