uni 下拉加载更多_uniapp上拉加载更多功能的简单实现

前提:安装了uniapp的LoadMore插件(一般初始都会安装此插件), https://ext.dcloud.net.cn/plugin?id=29

... //渲染的列表处

//loading加载提示处

export default {

data() {

return {

videoList:[],

page:1,

pagesize:10,

loadStatus:'loading', //加载样式:more-加载前样式,loading-加载中样式,nomore-没有数据样式

isLoadMore:false, //是否加载中

};

},

onLoad() {

this.getVideoList()

},

onReachBottom(){ //上拉触底函数

if(!this.isLoadMore){ //此处判断,上锁,防止重复请求

this.isLoadMore=true

this.page+=1

this.getVideoList()

}

},

methods:{

getVideoList(){

uni.request({

url: `${this.$baseUrl}/api-video/getlist?page=${this.page}&pagesize=${this.pagesize}`,

method: 'GET',

success: res => {

if(res.data.code==200){

if(res.data.data.list){

this.videoList=this.videoList.concat(res.data.data.list)

if(res.data.data.list.length

this.isLoadMore=true

this.loadStatus='nomore'

}else{

this.isLoadMore=false

}

}else{

this.isLoadMore=true

this.loadStatus='nomore'

}

}else{ //接口请求失败的处理

uni.showToast({title:res.data.msg,icon:'none'})

this.isLoadMore=false

if(this.page>1){

this.page-=1

}

}

},

fail: () => { //接口请求失败的处理

uni.showToast({title: '服务器开小差了呢,请您稍后再试',icon:'none'})

this.isLoadMore=false

if(this.page>1){

this.page-=1

}

},

});

},

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
uniapp中,可以使用uni的内置组件来实现下拉刷新和上划加载更多的功能。 下拉刷新是指在页面顶部下拉时触发的刷新操作。可以通过在页面的<template>中使用<uni-scroll-view>组件,并设置refresher属性为true,然后在<uni-scroll-view>组件的bindrefresh事件中添加下拉刷新的逻辑代码。具体实现如下: <template> <view> <uni-scroll-view refresher="{{ true }}" bindrefresh="onRefresh"> <view>下拉刷新内容</view> </uni-scroll-view> </view> </template> <script> export default { methods: { onRefresh() { // 下拉刷新逻辑代码 // 例如请求数据,新页面内容等操作 // 刷新完成后,调用uni.stopPullDownRefresh()方法停止下拉刷新的动画 } } } </script> 上划加载更多是指在页面底部上划时触发的加载更多操作。可以通过在页面的<template>中使用<uni-scroll-view>组件,并设置scroll-y属性为true,然后在<uni-scroll-view>组件的bindscrolltolower事件中添加上划加载更多的逻辑代码。具体实现如下: <template> <view> <uni-scroll-view scroll-y="{{ true }}" bindscrolltolower="onLoadMore"> <view>上划加载更多内容</view> </uni-scroll-view> </view> </template> <script> export default { methods: { onLoadMore() { // 上划加载更多逻辑代码 // 例如请求下一页数据,追加到页面内容中等操作 } } } </script> 通过以上方式,可以在uniapp实现下拉刷新和上划加载更多的功能,提升用户体验。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值