我有一個頁面轉換,當滾動到新路線頂部的滾動是即時的時,它不能很好地工作。我想等100毫秒才能自動滾動到頂端。下面的代碼根本不會最終滾動。有沒有辦法做到這一點?Vue.js在setTimeout之後滾動到新頁面路線的頂部
export default new Router({
mode: 'history',
routes: [
{
path: '/',
name: 'Home',
component: Home
}
],
scrollBehavior (to, from, savedPosition) {
setTimeout(() => {
return { x: 0, y: 0 }
}, 100);
}
})