原生小程序分页/上拉加载(通过页面生命周期)

/**

  • 页面的初始数据
    */
  data: {
    // 一页多少条
    pageSize: 10,
    // 在第多少页
    pageNo: 1,
    // 列表数据
    list: [],
  },

// 车辆列表接口

  getList() {
 
    getCars({
      page: this.data.pageNo,
      pagesize: this.data.pageSize
    }).then((res) => {
      console.log(res);
      // 停止下拉刷新操作
      wx.stopPullDownRefresh()
      // 返回有数据时
      if (res.data.list.length != 0) {
      // 如果是第一页
        if (this.data.pageNo == 1) {
          this.setData({
            list: res.data.list
          })
        } else {
        // 不是第一页 则要拼接上之前的列表
          this.setData({
            list: this.data.list.concat(res.data.list)
          })
        }
      } else {
        wx.showToast({
          title: '没有更多数据了!',
          icon: 'none',
          duration: 1500
        })
      }

    })
  },
  

/**

  • 页面上拉触底事件的处理函数
    */
  onReachBottom() {
  // 页面触底后 页码加一 并调用接口
    this.setData({
      pageNo: this.data.pageNo + 1
    })
    this.getList()
  },

最近更新

  1. TCP协议是安全的吗?

    2024-04-30 20:00:04       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-30 20:00:04       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-30 20:00:04       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-30 20:00:04       18 阅读

热门阅读

  1. Czi.算法学习(三)

    2024-04-30 20:00:04       12 阅读
  2. 表达式解析器MVEL的了解

    2024-04-30 20:00:04       9 阅读
  3. MSP未来趋势

    2024-04-30 20:00:04       8 阅读
  4. 【Spring AI】前言

    2024-04-30 20:00:04       11 阅读
  5. 【多维动态规划】Leetcode 72. 编辑距离【中等】

    2024-04-30 20:00:04       8 阅读
  6. Redis使用手册之字符串

    2024-04-30 20:00:04       15 阅读
  7. AtCoder Beginner Contest 351 A题 The bottom of the ninth

    2024-04-30 20:00:04       10 阅读