微信小程序 實現上拉加載更多


WXML 中

<view class="authorization_box">
  <view class="list" wx:for="{{datalist}}">
    <view class="name">{{item.name}}</view>
  </view>
  <block wx:if="{{dataILu}}">
    <view class="loadMore">正在加載中...</view>
  </block>
  <block wx:else>
    <view class="loadMore">沒有更多數據了</view>
  </block>
</view>

 

JS 中

data: {
    datalist:[],//數據列表
    dataILu : true,//是否還有更多數據
    pageIndex:0,
    pageSize:10
  },
onLoad: function (options) {
    this.getdata()//獲取數據
  },
getdata(){
    //如果沒有更多數據了就退出
    if ( ! this.data.dataILu ) return
    this.data.pageIndex++
    //獲取數據的接口
    api.get(`/api/user-auth-view-history/du-record?pageInfo.pageIndex=${this.data.pageIndex}&pageInfo.pageSize=${this.data.pageSize}`).then(res=>{
      console.log(res)
      if(res.code==200){
        const newList = [...this.data.datalist,...res.content.list]
        const total = res.content.count
        this.setData({
          datalist:newList,
          dataILu : newList.length < total
        })
      }
    })
  },
//頁面上拉觸底事件的處理函數
  onReachBottom: function () {
    this.getdata()//獲取數據
  },

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM