zoukankan      html  css  js  c++  java
  • 小程序上拉触底&下拉加载

    data: {
        pageNo: 1,//当前页
        pageSize: 10,//每页条数
        count:'',//总条数
        orderList: [],
    },
    onLoad: function () {
        var that = this;
        var data = `${that.data.type}/${that.data.pageSize}/${that.data.pageNo}`;
        that.getOrderList(data);
    },
    //订单列表
    getOrderList(data) {
        var that = this;
        var orderList = that.data.orderList;
        wx.showLoading({
          title: '加载中',
        })
        wx.request({
          url: `${host.orderList}/${data}`,
          header: {
            "content-type": "application/json",
          },
          success: function (res) {
            console.log(res);
            if (res.data.code == 0) {
              if (res.data.data.list && res.data.data.count > orderList.length) {
                var arr = res.data.data.list;
                arr.forEach(item => {
                  orderList.push(item);
                })
                that.setData({
                  orderList: orderList,
                  count: res.data.data.count,
                })
              }
            }
            else {
              wx.showToast({
                icon: 'none',
                title: res.data.msg,
              })
            }
          },
          complete: function () {
            setTimeout(() => {
              wx.hideLoading();
              wx.stopPullDownRefresh();
            }, 500)
          }
        })
    },
    /**
      * 页面相关事件处理函数--监听用户下拉动作
    */
      onPullDownRefresh: function () {
        var that = this;
        var data = `${that.data.type}/${that.data.pageSize}/${that.data.pageNo}`;
        that.getOrderList(data);
    },
    /**
       * 页面上拉触底事件的处理函数
    */
    onReachBottom: function () {
        var that = this;
        var pageNo =  that.data.pageNo;
        if (that.data.count > that.data.orderList.length){
          that.setData({
            pageNo: pageNo += 1,
            noMore: true,
          })
          var data = `${that.data.type}/${that.data.pageSize}/${pageNo}`;
          that.getOrderList(data);
        }
    },

    下拉触底需要在当前页面的json文件添加"enablePullDownRefresh": true或者在app.json window里面全局添加。

  • 相关阅读:
    隔离级别 && SNAPSHOT
    多态性&& 虚函数 && 抽象类
    socket编程
    [APIO2015]巴邻旁之桥
    LuoguP3701 「伪模板」主席树
    线段树标记永久化
    [HNOI2015]开店
    NOIP2017划水记
    FFTNTT总结
    [THUWC 2017]在美妙的数学王国中畅游
  • 原文地址:https://www.cnblogs.com/pycmsj/p/12103065.html
Copyright © 2011-2022 走看看