您的位置:首页 > 房产 > 建筑 > uni-app中分页器的实现

uni-app中分页器的实现

2024/10/7 8:29:05 来源:https://blog.csdn.net/weixin_51480428/article/details/141603344  浏览:    关键词:uni-app中分页器的实现

一、template

change函数在每次点击上一页 或者写一页的时候会触发,其传递的参数是当前的current页数

<uni-section class="fixed-bottom" title="默认样式" type="line" padding><uni-pagination @change="handleList" :current="current" :pageSize="8" :total="total" title="标题文字"/>
</uni-section>

二、data

     LicenceNum : undefined,  //查询须要的参数checkList: [],total: 0,current: 1

三、methods函数

      handleList(e) {console.log(e, 'eeeeeeeeeeeee')this.current = e.currentlet obj = {pageSize: 8,pageNum: e.current,}checkList(this.LicenceNum ,obj).then(res => {this.checkList = res.rows})}

四、onLoad函数

        onLoad(e) {this.LicenceNum = e.num;this.userId = e.userIdlet obj = {pageSize: 8,pageNum: 1}checkList(e.num, obj).then(res => {console.log(res, 'ddd')this.total = res.totalthis.checkList = res.rows})}

五、总结

刚进页面的时候,接收上一个页面传递过来的查询参数,此时调用后端查询接口,这时候的pageSize和pageNum值是固定的,默认查询第一页,同时将数据总条数设置给total,组件会自动根据你设置的pageSize大小和后端查询出的total计算出总的页数。后面就是用户点击上一页或者下一页按钮来触发change函数,传来当前的页数,你再去调用接口查询当前页码的数据即可。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com