当监听数据更新后,再次触发初始化,页面列表自动滚动到顶部,要想保持原位置,禁止当前滚动即可。
这里只会这个方法,如果有更好的方法,欢迎解答。
官方文档里有stop方法
stop()
- 参数:无
- 返回值:无
- 作用:立即停止当前运行的滚动动画。
init() {
this.listScroll =new BScroll('.wrapper',{
probeType: 3,
startY:true,
click:true,
mouseWheel: true,//开启鼠标滚轮
disableMouse: false,//启用鼠标拖动
disableTouch: false//启用手指触摸
})
this.listScroll.stop()//初始化禁止滚动----加个stop方法,防止自动滚动到顶部
this.listScroll.on('touchEnd',(pos)=>{
if (pos.y >50) {
console.log('触发上拉刷新');
}
if (this.listScroll.maxScrollY > pos.y+20) {
console.log('触发下拉加载更多');
this.reqpublishlist()
}
})
}