uni-app 触底加载和下拉刷新
//获取热门商品列表数据async getGoodsList(callBack){const res = await this.$myRequest({url:'/public/v1/goods/search',data:{pagenum: this.pagenum,//当前页数pagesize: this.pagesize//每页显示条数}})this.total = res.data.mess
·
//获取热门商品列表数据
async getGoodsList(callBack){
const res = await this.$myRequest({
url:'/public/v1/goods/search',
data:{
pagenum: this.pagenum,//当前页数
pagesize: this.pagesize//每页显示条数
}
})
this.total = res.data.message.total//总条数
this.goods = [...this.goods,...res.data.message.goods]//追加新数据
callBack && callBack()
},
//初次加载触发
onLoad(){
this.getGoodsList()
},
//触底后触发
onReachBottom(){
if(this.goods.length == this.total) return this.flag = true//如果数组长度等于总条数 显示“我是有底线的”
this.pagenum++
this.getGoodsList()
},
//监听下拉刷新
onPullDownRefresh(){
this.pagenum = 1
this.goods = []
this.flag = false
this.getGoodsList(()=>{
uni.stopPullDownRefresh()//停止下拉刷新动画
})
},
更多推荐
已为社区贡献1条内容
所有评论(0)