小程序上拉触底&下拉加载

小程序上拉触底&下拉加载
 1 data: {
 2     pageNo: 1,//当前页
 3     pageSize: 10,//每页条数
 4     count:'',//总条数
 5     orderList: [],
 6 },
 7 //订单列表
 8 getOrderList(data) {
 9     var that = this;
10     var orderList = that.data.orderList;
11     wx.showLoading({
12       title: '加载中',
13     })
14     wx.request({
15       url: `${host.orderList}/${data}`,
16       header: {
17         "content-type": "application/json",
18       },
19       success: function (res) {
20         console.log(res);
21         if (res.data.code == 0) {
22           if (res.data.data.list && res.data.data.count > orderList.length) {
23             var arr = res.data.data.list;
24             arr.forEach(item => {
25               that.data.orderList.push(item);
26             })
27             that.setData({
28               orderList: orderList,
29               count: res.data.data.count,
30             })
31           }
32         }
33         else {
34           wx.showToast({
35             icon: 'none',
36             title: res.data.msg,
37           })
38         }
39       },
40       complete: function () {
41         setTimeout(() => {
42           wx.hideLoading();
43           wx.stopPullDownRefresh();
44         }, 500)
45       }
46     })
47 },
48 /**
49   * 页面相关事件处理函数--监听用户下拉动作
50 */
51 onPullDownRefresh: function () {
52     var that = this;
53     var data = `${that.data.type}/${that.data.pageSize}/${that.data.pageNo}`;
54     that.getOrderList(data);
55 },
56 /**
57    * 页面上拉触底事件的处理函数
58 */
59 onReachBottom: function () {
60     var that = this;
61     var pageNo =  that.data.pageNo;
62     if (that.data.count > that.data.orderList.length){
63       that.setData({
64         pageNo: pageNo += 1,
65         noMore: true,
66       })
67       var data = `${that.data.type}/${that.data.pageSize}/${pageNo}`;
68       that.getOrderList(data);
69     }
70 },
View Code
上一篇:在SpringBoot或者Spring项目中实现最原始的分页功能


下一篇:SSM框架手动实现分页逻辑(非PageHelper)