在main.js中采用全局守卫设置高度距离
router.beforeEach((to, from, next) => {
// 让页面回到顶部
// chrome
document.body.scrollTop = 0;
// firefox
document.documentElement.scrollTop = 0;
// safari
window.pageYOffset = 0;
next()
})
注意:一定要调用 next 方法,否则钩子就不会被销毁。
希望对你有所帮助