欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序?qū)崿F(xiàn)列表下拉刷新上拉加載

 更新時(shí)間:2020年07月29日 14:48:31   作者:Rattenking  
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)列表下拉刷新上拉加載,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)列表下拉刷新上拉加載的具體代碼,供大家參考,具體內(nèi)容如下

DEMO下載

效果圖

原理

利用微信小程序的onPullDownRefresh函數(shù)(下拉刷新監(jiān)聽函數(shù))和onReachBottom函數(shù)(上拉加載監(jiān)聽函數(shù))監(jiān)聽頁面的下拉和上拉動(dòng)態(tài),從而對(duì)頁面數(shù)據(jù)進(jìn)行修改!

頁面配置JSON

  • enablePullDownRefresh:開啟下拉刷新;
  • onReachBottomDistance:頁面上拉觸底事件觸發(fā)時(shí)距頁面底部距離,單位為px。
{
 "enablePullDownRefresh": true,
 "onReachBottomDistance": 50
}

WXML

<view class="tui-content">
 <view class="tui-menu-list" wx:for="{{dataList}}">Item -- {{item}}</view>
</view>

JS

此處用setTimeout模擬請(qǐng)求數(shù)據(jù);
加載數(shù)據(jù)限制三次,調(diào)用wx.showToast顯示沒有更多數(shù)據(jù)。

Page({
 data: {
 dataList: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],
 count : 0
 },
 onPullDownRefresh(){
 var self = this;
 setTimeout(() => {
 // 模擬請(qǐng)求數(shù)據(jù),并渲染
 var arr = self.data.dataList, max = Math.max(...arr);
 for (var i = max + 1; i <= max + 3; ++i) {
 arr.unshift(i);
 }
 self.setData({ dataList: arr });
 // 數(shù)據(jù)成功后,停止下拉刷新
 wx.stopPullDownRefresh();
 }, 1000);
 },
 onReachBottom(){
 var arr = this.data.dataList, max = Math.max(...arr);
 if (this.data.count < 3) {
 for (var i = max + 1; i <= max + 5; ++i) {
 arr.push(i);
 }
 this.setData({
 dataList: arr,
 count: ++this.data.count
 });
 } else {
 wx.showToast({
 title: '沒有更多數(shù)據(jù)了!',
 image: '../../src/images/noData.png',
 })
 }
 }
})

總結(jié)

必須在每次數(shù)據(jù)請(qǐng)求完成后,使用wx.stopPullDownRefresh()停止下拉刷新。

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論