微信小程序上拉加载和下拉刷新功能实现 |
微信小程序上拉加载和下拉刷新一.上拉加载微信小程序的上拉加载使用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()会监听微信小程序上拉操作 。 "onReachBottomDistance": 50px 二.下拉刷新下拉刷新使用onPullDownRefresh() onPullDownRefresh(){
//下拉刷新后,显示1,2,3
this.setData({
numList:[1,2,3]
})
if(this.data.numList.length === 3){
wx.stopPullDownRefresh()
}
}注意,在使用onPullDownRefresh() 的时候,需要及时使用wx.stopPullDownRefresh()进行关闭,不然可能会长时间显示刷新状态
微信小程序开发---上拉触底一、上拉触底的概念
二、监听页面的上拉触底事件
onReachBottom(){
console.log("上拉")
}三、配置上拉触底距离
"onReachBottomDistance": 100 到此这篇关于微信小程序上拉加载和下拉刷新的文章就介绍到这了,更多相关小程序上拉加载和下拉刷新内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持! |