刚巧做个这个,贴一下我已的一个方案。
整个应用是基于 VUE + WEBPACK
使用了VUE-ROUTER + VUEX
VUE-ROUTER 自身会有栅格钩子函数 data , activate ,deactivate
当A->B时,记录A中你的列表位置(列表数据是VUEX中的,“.forum-infinite-scroll” 用来定位你的列表)
deactivate ({to, next}) {
this.pos = $(this.$el).find('.forum-infinite-scroll').offset()
next()
}
当B->A时,移动到原位置
deactivate ({to, next}) {
this.pos = $(this.$el).find('.forum-infinite-scroll').offset()
if (this.pos && this.pos.top < 0) {
let scroller = $(this.$el).find('.infinite-scroll-bottom')
setTimeout(()=>{
this.$nextTick(function () {
$.refreshScroller()
scroller.scrollTop(Math.abs(this.pos.top) + 250)
})
}, 500)
}
next()
}
这里有几个地方需要注意,
一是 this.$nextTick
二是 $.refreshScroller()
缺一不可