微信小程序,uniapp的底部加载,滚动到底部刷新onReachBottom

目录

onReachBottom了解

onReachBottom注意项:

事件具体写法:

uni-load-more了解(不重要可自行考虑是否添加)

getList事件具体(通过接口获取列表的事件)

concat拼接:


onReachBottom了解

使用uniapp的onReachBottom():页面滚动到底部的事件(不是scroll-view滚到底),常用于下拉下一页数据。

onReachBottom()具体了解可以查看官方api:页面简介 | uni-app官网

onReachBottom注意项:

这个事件需要写在和data(){}同级。并且你的页面不能写死。不然不会触发底部刷新。比如样式加了个{position:fixed;top:0;botton:0;left:0;right:0}

事件具体写法:

onReachBottom() {
		// 判断是否有数据
                //(数据的每页显示条数乘以数据页数)是否大等于(总数据)
				if (this.pageInfo.page * this.pageInfo.size >= this.pageInfo.total) {
                    //把状态改成没数据(这边使用了uniapp的uni-load-more,把uni-load-more的标签:start='start',这个start就动态绑定了显示是否有数据加载或者显示暂无数据)
					this.status = "noMore"
					return;
				} else {
                   //(数据小于总条数,说明还有数据执行)
					this.status = "loading"
                    //传给后端获取列表的接口值中,page++
					this.pageInfo.page++
                    //设置个状态给getList获取列表的事件,在事件中判断,如果是loading,则只执行page++获取到的数据,拼接到前面的数据。(这边可以看getList的事件)
					this.getList('loading'); // 获取数据
				}
		},

uni-load-more了解(不重要可自行考虑是否添加)

uni-load-more标签写在template(这个只是用来显示暂无数据和加载的样式而已。和底部刷新你不加也行。好看的)

​
<uni-load-more v-if='dataSource.length > 0' :status="status"></uni-load-more>

​

getList事件具体(通过接口获取列表的事件)

getList(type){
this.Api(this.pageInfo.page).then(res => {
					const total = res.total
                    //显示暂无数据或者。。。。
					this.status = this.pageInfo.page * this.pageInfo.size >= total ? 'noMore' : 'more'
					this.pageInfo.total = total
                    //传了loading的刷新:是底部刷新
					if (type === 'loading') {
                       //通过concat拼接数组
						this.dataSource = this.dataSource.concat(res.list)
					} else {
						this.dataSource = res.list
					}
				})
}

concat拼接:

let a =[1,2,3]
a.concet(6.5)
console.log(a) //这边就输出[1,2,3,6,5]
  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值