鍍金池/ 問答/HTML/ vue2.0 - vue-router跳轉(zhuǎn)滾動條返回頂部

vue2.0 - vue-router跳轉(zhuǎn)滾動條返回頂部

在main.js中配置
router.afterEach((to, from, next) => {
window.scrollTo(0, 0)
})
或index.js配置
scrollBehavior (to, from, savedPosition) {
return { x: 0, y: 0 }
}
都無效果,還有別的方法嗎?各位大佬

回答
編輯回答
誮惜顏

scrollBehavior (to, from, savedPosition) {

return { x: 0, y: 0 }

}

2017年1月7日 12:05
編輯回答
夢一場

加上一個定時器試試

router.afterEach((to, from, next) => {
 setTimeout(function() {
        window.scrollTo(0, 0)
    },100)
})
2018年5月31日 12:55
編輯回答
單眼皮

試試這個

router.afterEach((to, from, next) => {
    document.documentElement.scrollTop = 0
    document.body.scrollTop = 0
})
2017年10月16日 00:31