微信小程序--上拉加载详解

125 阅读1分钟

index.wxml:

<scroll-view scroll-y style="height:100vh;" bindscrolltolower="lower" scroll-into-view="{{toView}}" scroll-top="{{scrollTop}}">
  <view class='content-wrapper' upper-threshold>
	//此处为上拉加载的类别页样式
  </view>
</scroll-view>

注:style="height:100vh;"表示监听当前视窗区域,超出当前的可视区域即触发bindscrolltolower="lower"

index.js:

 lower: function (e) { // 上拉加载
    console.log(e)
    //此处为上拉加载请求代码
  },

Tips:如果开发中需要多层scroll-view滚动,scroll-view会出现滑动穿透,这时候bindscrolltolower可以改为catchtouchmove即可。

Ps:upper-threshold 是允许纵向滚动