1.vue
1.1 vue3中用scrollBehavior 的top属性
const router = createRouter({
scrollBehavior (to, from, savedPosition) {
return { top: 0 }
},
})
1.2 vue2中用 scrollBehavior 的y属性
const config = {
base: process.env.VUE_APP_ROUTE_BASE,
routes,
scrollBehavior (to, from, savedPosition){
return { y: 0 }
}
}
const router = new Router(config)
2.路由中置顶
router.afterEach(to => {
document.getElementById('app').scrollTop = 0
})