这样不起作用,怎么滑动都是0;
这样就可以了;
route是这样的:
export default new Router({
mode: 'history',
scrollBehavior (to, from, savedPosition) {
if (savedPosition) {
console.log(savedPosition)
return savedPosition
} else {
return { x: 0, y: 0 }
}
},
routes: [
{
path: '/',
component: List
},
{
path:'/topic/:id',
component:Detail
}
]
})
回复 (8)
Z
刚刚在看滚动行为的时候,一直看不懂是什么意思,看到你的代码,恍然间有点明白了
source vue-cnode mobile 2.0
G
Z
有这么一段代码const scrollTop = (el, value) => { const hasScrollTop = 'scrollTop' in el if (value === undefined) return hasScrollTop ? el.scrollTop : el.pageYOffset if (hasScrollTop) { el.scrollTop = value } else { el.scrollTo(el.scrollX, value) } },看了scrollBehavior()就知道刚刚那段代码什么意思了
source vue-cnode mobile 2.0
G
Z
别人的开源代码
source vue-cnode mobile 2.0
G
引用 zbb1211别人的开源代码 source vue cnode mobile 2.0
@zbb1211 链接我看看,谢谢大兄弟
Z
G
参与回复
登录后即可参与回复。登录