【 微信小程序 】上拉触底事件

上拉触底

手指在屏幕上的上拉滑动操作 从而加载更多数据

页面上拉触底事件触发时距页面的距离 默认50px (滚动条距离底部的距离 自动加载更多数据)
	"onReachBottomDistance" : Number

页面相关事件处理函数

Page({
	data:{},
	// 监听上拉触底事件
  	onReachBottom(){
    	console.log('上拉触底');
  	}
})

配置上拉触底距离

{
  "usingComponents": {},
  "onReachBottomDistance" : 100
}

上拉触底设置节流

Page({
	data:{  
		colorList:[],
		// 1.在data中设置节流阀 isLoading false(没有请求数据) / true(正在请求数据)
        isLoding:false
	},
	// 2.在监听上拉触底事件中执行的函数里面修改isLoading的值
 	 getColors(){
 	 	// 将节流阀设置为 true
        this.setData({
            isLoding:true
        })
        wx.showLoading({
          title: '加载中。。。。。。'
        })
        wx.request({
          url: 'https://www.escook.cn/api/color',
          method:"GET",
          success:({data:res})=>{
              console.log(res);
              this.setData({
                colorList:[...this.data.colorList,...res.data]
              })
          },
          complete:()=>{
              wx.hideLoading()
              // 将节流阀设置为 false
              this.setData({
                isLoding:false
            })
          }
        })
    },
	// 3.在onReachBottom中判断节流阀的值 对数据进行控制
	onReachBottom: function () {
		// true 阻止请求
        if(this.data.isLoding){
            return
        }else{
        	// false 发起请求
            this.getColors()
        }
    },
})
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值