vue-scroller
vue-scroller copied to clipboard
切换路由会不断执行onInfinite方法,切换路由之后不能记忆滚动条高度(在使用了keep-alive的情况下)
这里简单的判断了宽高为0的情况,希望作者能及时的修复这类bug Scroller.vue line number :344
let flag = this.content.offsetHeight && this.container.clientHeight // 宽高不为0
flag = flag && (top + 60 > this.content.offsetHeight - this.container.clientHeight )
if (flag) {
if (this.loadingState) return
this.loadingState = 1
this.showLoading = true
this.onInfinite(this.finishInfinite)
}
Scroller.vue line number :383
let flag = width !== content_width || height !== content_height
flag = flag && width && height // 宽高不为0
if (flag) {
content_width = width
content_height = height
this.resize()
}
遇到同样类似的问题!
你照着上面的代码弄一下,会比之前的情况要好一些。
目前版本2.2.2依然存在上述问题(使用了keep-alive 切换路由会不断执行onInfinite方法)
master 上已经修复,版本还没有发
我已经替换成master的代码,问题依旧存在,情况是在A页面切换到B页面之后会执行A页面的onInfinite方法 ,如果再切到A页面会执行B页面的onInfinite方法(两个页面都有scroller)并且数据要超过一屏才会触发
大神,这个问题怎么解决?,我也遇到这个问题
我是这样解决的 // enable infinite loading if (this.onInfinite) { this.infiniteTimer = setInterval(() => { let { left, top, zoom } = this.scroller.getValues() //避免页面一开始或者切换路由时执行 onInfinite 方法 if (this.content.offsetHeight > this.container.clientHeight) { if (top - 30 > this.content.offsetHeight - this.container.clientHeight) { if (this.loadingState) return this.loadingState = 1 this.showLoading = true this.onInfinite(this.finishInfinite) } }
}, 10);
}
同样使用了keep-alive 我是这样记录滚动的 页面离开时 const data = this.$refs.giftScroll.getPosition() this.$store.commit('setScroll', data) this.$router.push({ name: 'gameDetails', params: {gameId: id} }) 页面返回时 activated() { if (this.scrollState) { setTimeout(() => { this.$refs.giftScroll.scrollTo(this.scrollState.left, this.scrollState.top, false) }, 30) } },
更新到 2.2.3 再试试看
页面离开时,const data = this.$refs.giftScroll.getPosition(), 获取不到 data啊
@silverpeng 你将路由跳转绑定到click里去,别写在router-link里面,执行点击事件的时候记录位置
获取到的数据尽量别存当前组件,最好是存vuex或cookie之类的
嗯,解决了 , 还有一个问题 怎么判断前进还是后退呢?比如,我点击列表,跳转后返回,保存滚动条位置, 但是 我重新进入的时候 不要保存滚动条位置
A=>B=>C=>B,保存滚动条, B=>A=>B,不要滚动条位置
@silverpeng vue路由的beforeEach钩子,或者vue的watch都可以监听到后退还是前进
嗯,非常感谢,解决了,组件很不错 赞一个
就是 假如这个组件不keep-alive,总会报错,这个问题 希望大神你能解决一哈
@silverpeng 不 keep-alive
是指去掉这个 <keep-alive>
wrapper 吗?https://github.com/wangdahoo/vue-scroller/blob/master/demo/App.vue#L3
这个问题是还没解决么?