// 在路由文件中添加scrollBehavior
// 注意此方法只针对浏览器的前进后退有效
const router = createRouter({
history: createWebHashHistory(),
routes: [{
path: '/',
component: defineAsyncComponent(() => import('../views/homepage.vue'))
},
{
path: '/page1',
component: defineAsyncComponent({loader: () => import('../views/page1.vue'), timeout: 5000, delay: 5000})
}],
scrollBehavior( to, from, savedPosition){
// 如果有记录页面的滚动行为
if(savedPosition){
return savedPosition
}else{
return { top: 0 }
}
}
})
07-23
837
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
10-11