微信小程序上拉加载和下拉刷新
一.上拉加载
微信小程序的上拉加载使用onreachbottom(),写在.js文件里面的page方法里面。
onreachbottom(){ //上拉自动更新到4,5,6 wx.showloading({ title: '数据加载中...', }) settimeout(()=>{ const lastnum=this.data.numlist[this.data.numlist.length-1] const newary=[lastnum+1,lastnum+2,lastnum+3] this.setdata({ numlist:[...this.data.numlist,...newary] }) wx.hideloading() },1500) }
onreachbottom()会监听微信小程序上拉操作。
需要在.json文件里面配置"onreachbottomdistance"属性。
如下面的代码,在距离底部50px的时候会触发到onreachbottom()
"onreachbottomdistance": 50px
二.下拉刷新
下拉刷新使用onpulldownrefresh()
onpulldownrefresh(){ //下拉刷新后,显示1,2,3 this.setdata({ numlist:[1,2,3] }) if(this.data.numlist.length === 3){ wx.stoppulldownrefresh() } }
注意,在使用onpulldownrefresh() 的时候,需要及时使用wx.stoppulldownrefresh()进行关闭,不然可能会长时间显示刷新状态
微信小程序开发---上拉触底
一、上拉触底的概念
上拉触底是移动端的专有名词,通过手指在屏幕上的上拉滑动操作,从而加载更多的数据,也就是往下滑动。
二、监听页面的上拉触底事件
在页面.js文件宗,通过onreachbottom()函数即可监听当前页面的上拉触底事件
onreachbottom(){ console.log("上拉") }
三、配置上拉触底距离
上拉触底距离指的是触发上拉触底事件时,滚动条距离页面底部的距离。
可以在全局或者页面的.json文件中,通过onreachbottomdistance属性配置上拉触底的距离
小程序默认的距离是50px
"onreachbottomdistance": 100
到此这篇关于微信小程序上拉加载和下拉刷新的文章就介绍到这了,更多相关小程序上拉加载和下拉刷新内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论