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()//獲取數據 },