小程序的两种分页做法(后端返回分页及总页数字段与否)


1.带分页

 onReachBottom:function () {
         // 如果还未到最后一页,继续加载
        if(this.data.page < this.data.last_page){
            this.setData({
                page:this.data.page+1
            })
            this.getProductList(false)
        }
    },
last_page接口获取;

2.不带分页
onReachBottom: function () {
        // 如果还未到最后一页,继续加载
        if (this.data.loadMore) {
            this.setData({
                page: this.data.page + 1
            })
            this.getProductList(false)
        }
    },

loadMore需做的处理:

 if (res.data.data.length === 0 && _this.data.page !== 1) {
                        _this.setData({
                            loadMore: false
                        })
                        wx.showToast({
                            title: '没有更多内容啦!',
                            icon: 'none'
                        });
                    }

 

两者需要做统一处理的地方:

this.getProductList(false)  --分页请求
this.getProductList()  --非分页请求
 if (isReset) {
                        _this.setData({
                            productList: res.data.data,
                            // last_page:res.data.pagination.last_page,
                        })
                    } else {
                        _this.setData({
                            productList: _this.data.productList.concat(res.data.data),
                            // last_page:res.data.pagination.last_page,
                        })
                    }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM