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

/**

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

// 车辆列表接口

js 复制代码
  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
        })
      }

    })
  },
  

/**

  • 页面上拉触底事件的处理函数
    */
js 复制代码
  onReachBottom() {
  // 页面触底后 页码加一 并调用接口
    this.setData({
      pageNo: this.data.pageNo + 1
    })
    this.getList()
  },
相关推荐
头发还在的女程序员5 小时前
基于JAVA语言的短剧小程序-抖音短剧小程序
java·开发语言·小程序
2501_916007479 小时前
iOS 应用性能测试的工程化流程,构建从指标采集到问题归因的多工具协同测试体系
android·ios·小程序·https·uni-app·iphone·webview
book多得11 小时前
刷题专用微信小程序推荐
微信小程序·小程序
00后程序员张12 小时前
iOS 抓不到包怎么办?从 HTTPS 解密、QUIC 排查到 TCP 数据流分析的完整解决方案
android·tcp/ip·ios·小程序·https·uni-app·iphone
技术与健康14 小时前
微信小程序云开发实践:共享环境与LLM整合经验
微信小程序·小程序
老华带你飞15 小时前
社区养老保障|智慧养老|基于springboot+小程序社区养老保障系统设计与实现(源码+数据库+文档)
java·数据库·vue.js·spring boot·小程序·毕设·社区养老保障
发财北16 小时前
本地生活小程序开发方案
小程序
游戏开发爱好者81 天前
iOS 商店上架全流程解析 从工程准备到审核通过的系统化实践指南
android·macos·ios·小程序·uni-app·cocoa·iphone
hyswl6661 天前
2025年开发小程序公司推荐
python·小程序
kdniao11 天前
电商平台与小程序与快递鸟物流轨迹API
小程序