Vue切换页面滚动条回到顶部

router—index.js

router.afterEach((to,from)=>{
  window.pageYOffset = 0
  document.body.scrollTop = 0
  document.documentElement.scrollTop = 0
})

App.vue

watch: {
  '$route': function(to,from){
    window.pageYOffset = 0
    document.body.scrollTop = 0
    document.documentElement.scrollTop = 0
  }
}

你可能感兴趣的:(Vue切换页面滚动条回到顶部)