当立即滚动到新路线的顶部时,我的页面转换效果不佳。我想等待 100 毫秒,然后它会自动滚动到顶部。以下代码根本不会滚动。有没有办法做到这一点?
export default new Router({
mode: 'history',
routes: [
{
path: '/',
name: 'Home',
component: Home
}
],
scrollBehavior (to, from, savedPosition) {
setTimeout(() => {
return { x: 0, y: 0 }
}, 100);
}
})
这是原生支持的Vue现在,使用scrollBehaviour
, 像这样:
export default new Router({
scrollBehavior() {
return { x: 0, y: 0 };
},
routes: [
{
path: '/',
name: 'Home',
component: Home
}
],
mode: 'history'
});
更多这里 https://router.vuejs.org/guide/advanced/scroll-behavior.html.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)