小編給大家分享一下微信小程序中如何實(shí)現(xiàn)列表上拉加載,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!

某個(gè)頁面,有多個(gè)列表,如100行,這時(shí)需要實(shí)現(xiàn)分頁功能,手機(jī)端的分頁一般都是滑到底部時(shí)上拉刷新。
使用scroll-view實(shí)現(xiàn),其bindscrolltolower方法:滾動(dòng)到底部/右邊觸發(fā)。當(dāng)觸發(fā)時(shí)發(fā)送請求獲取新的數(shù)據(jù),我寫的時(shí)候獲取的數(shù)據(jù)很快,我還給它加了個(gè)定時(shí)器啊哈哈哈,因?yàn)槲蚁胱宻howLoading加載彈窗轉(zhuǎn)一轉(zhuǎn),讓用戶知道上拉刷新數(shù)據(jù)。因?yàn)闆]加的時(shí)候showLoading一閃而過,感覺體驗(yàn)效果不好。
最后scroll-view使用豎向滾動(dòng)時(shí),需要給<scroll-view/>一個(gè)固定高度(height:93%),再給page設(shè)置高度(height:100%),否則bindscrolltolower觸發(fā)不了
<scroll-view wx:if="{{isShowList}}" class='scrollHeight' scroll-y="true" bindscrolltolower="getMore" lower-threshold='3'>
</scroll-view>來一段邏輯的代碼
//上拉加載分頁
getMore(e){
var that = this;
var user = wx.getStorageSync('bizUser');
wx.showLoading({
title: '正在加載中',
});
setTimeout(function(){
var pageindex = that.data.curPage;
var student = that.data.student;
if (pageindex>=1){
++pageindex;
}
wx.request({
url: app.url + '',
data: {
schoolId: user.schoolId,
pageSize: 10,
curPage:pageindex
},
method: 'GET',
success:function(res){
if (res.data.data) {
var studentLength = (res.data.data instanceof Array) ? res.data.data.length : 0;
for (var i = 0; i < studentLength; i++) {
//判斷計(jì)時(shí)付或一次性
if (res.data.data[i].sign_type == 2) {
res.data.data[i].sign_type = '一次性';
} else if (res.data.data[i].sign_type == 1) {
res.data.data[i].sign_type = '計(jì)時(shí)付';
} else if (res.data.data[i].sign_type == 3) {
res.data.data[i].sign_type = '計(jì)時(shí)付';
} else if (res.data.data[i].sign_type == 4) {
res.data.data[i].sign_type = '一次性';
} else if (res.data.data[i].sign_type = 5) {
res.data.data[i].sign_type = '一次性'
}
//數(shù)字變中文
if (res.data.data[i].learn_stage == 1) {
res.data.data[i].learn_stage = '一';
} else if (res.data.data[i].learn_stage == 2) {
res.data.data[i].learn_stage = '二';
} else if (res.data.data[i].learn_stage == 3) {
res.data.data[i].learn_stage = '三'
}
}
if (studentLength ==10) {
for (var j = 0; j < studentLength;j++){
student.push(res.data.data[j]);
}
that.setData({
student: student,
load: '上拉加載更多..',
curPage: pageindex
})
} else if (studentLength<10){
for (var j = 0; j < studentLength; j++) {
student.push(res.data.data[j]);
}
that.setData({
student: student,
load: '已經(jīng)沒有更多了..',
curPage: pageindex
})
}
} else {
that.setData({
load: '已經(jīng)沒有更多了'
})
}
}
})
wx.hideLoading();
},500)
},看完了這篇文章,相信你對“微信小程序中如何實(shí)現(xiàn)列表上拉加載”有了一定的了解,如果想了解更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!
分享標(biāo)題:微信小程序中如何實(shí)現(xiàn)列表上拉加載-創(chuàng)新互聯(lián)
文章轉(zhuǎn)載:http://www.jbt999.com/article5/dehsoi.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、企業(yè)建站、網(wǎng)站改版、服務(wù)器托管、網(wǎng)站內(nèi)鏈、定制網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:[email protected]。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容