小程序图片列表的头部下拉刷新和底部上拉加载备忘

1、设置页面刷新和滚动属性

    backgroundTextStyle:设置下拉背景字体、loading 图的样式,设置为黑色  
    enablePullDownRefresh:设置是否开启下拉刷新,设置为true

    disableScroll:设置为页面整体是否不可以上下滚动,设置为false

{
  "backgroundTextStyle": "dark", 
  "enablePullDownRefresh": true,
  "disableScroll": false 
}

2、修改下拉动作处理函数onPullDownRefresh和上拉触底事件处理函数onReachBottom

const app = getApp()
var array = []

Page({
  data: {
    catid: 430,
    imgList: []
  },

  /**
   * 请求图片
   */
  loadImgList: function (that) {
    var currCatid = that.data.catid
    //console.log("当前页数:", currCatid)
    wx.request({
      url: 'https://xxx?catid=' + currCatid,
      data: {},
      header: { 'content-type': 'application/json;charset=utf-8' },
      success: function (res) {
        if (res != null && res != undefined && res.data.ret == 'succ') {
          for (var index in res.data.sucais) {
            array.push(res.data.sucais[index])
          }
          that.setData({
            catid: currCatid + 1,
            imgList: array
          })
        }
        //console.log("图片获取返回结果:", that.data.imgList)
      }
    })
  },

  onLoad: function () {
    this.loadImgList(this)
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    console.log('顶部下拉刷新')
    this.data.catid = 1
    array = []
    this.loadImgList(this)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log('底部上拉追加新的一页')
    this.loadImgList(this)
  },
})

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值