请先看 Promise 分装 wx.request,否则可能看不懂以下内容
如const app=getApp()
app.http.list('pop',this.data.pageNo).then(res => {}
点击上方一步一步走
1 2 3 4 5 6 7 8 9
| <scroll-view scroll-y lower-threshold="100" bindscrolltolower="scrollToLower" style="height: 100vh;"> //中间是数据
<view style="text-align: center;margin: 10px;"> <view wx:if="{{loading}}">加载中...</view> <view wx:if="{{noMore}}">没有更多了</view> <view wx:if="{{loadingFailed}}">数据加载失败,请重试</view> </view> </scroll-view>
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| const app = getApp() Page({
data: { list: [], pageNo: 1, loading: false, loadingFailed: false, noMore: false, }, scrollToLower: function (e) { if (!this.data.loading ){ this.setData({ loading: true, pageNo: this.data.pageNo + 1 }) this.getData(true); } }, getData(isPage) { app.http.list('pop',this.data.pageNo).then(res => { this.setData({ loading: false }) if (res.data.data.page ) { if (isPage) { this.setData({ list: this.data.list.concat(res.data.data.list) }) } else { this.setData({ }) } if (res.data.data.list.length == 0) { this.setData({ noMore: true }) } } else { this.setData({ loadingFailed: true }) }
})
},
})
|