uni 下拉加载更多_uni-app 上拉加载更多

本文展示了在uni-app中实现下拉刷新和上拉加载更多的详细代码。通过`onPullDownRefresh`和`onReachBottom`事件监听,结合定时器实现延迟加载,更新数据并显示加载状态。
摘要由CSDN通过智能技术生成

完整代码

{{item}}

{{loadingText}}

var _self, page = 1, timer = null;

export default {

data:{

newsList:[],

loadingText:'加载中...'

},

onLoad:function(){

_self = this;

this.getnewsList();

},

onPullDownRefresh:function(){

this.getnewsList();

},

onReachBottom:function(){

if(timer != null){

clearTimeout(timer);

}

timer = setTimeout(function(){

_self.getmorenews();

}, 1000);

},

methods:{

getmorenews : function(){

if(_self.loadingText != '' && _self.loadingText != '加载更多'){

return false;

}

_self.loadingText = '加载中...';

uni.showNavigationBarLoading();

uni.request({

url: 'https://demo.hcoder.net/index.php?user=hcoder&pwd=hcoder&m=list1&page='+page,

method: 'GET',

success: function(res){

_self.loadingText = '';

if(res.data == null){

uni.hideNavigationBarLoading();

_self.loadingText = '已加载全部';

return false;

}

page++;

console.log(res);

_self.newsList = _self.newsList.concat(res.data.split('--hcSplitor--'));

_self.loadingText = '加载更多';

uni.hideNavigationBarLoading();

}

});

},

getnewsList : function(){

page = 1;

uni.showNavigationBarLoading();

uni.request({

url: 'https://demo.hcoder.net/index.php?user=hcoder&pwd=hcoder&m=list1&page=1',

method: 'GET',

success: function(res){

page++;

_self.newsList = res.data.split('--hcSplitor--');

uni.hideNavigationBarLoading();

uni.stopPullDownRefresh();

_self.loadingText = '加载更多';

}

});

}

}

}

.newslist{padding:10px; line-height:60px; font-size:28px;}

.loading{text-align:center; line-height:80px;}

实现原理请观看本节视频教程!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值