请先看 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
// pages/home/home.js
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 (err) {//返回失败
// this.setData({
// loadingFailed: true
// })
// return false;
// }
if (res.data.data.page ) {
if (isPage) {
//下一页的数据拼接在原有数据后面
this.setData({
list: this.data.list.concat(res.data.data.list)
})
} else {
//第一页数据直接赋值
this.setData({
//list: res.data.data.list
})
}
//如果返回的数据为空,那么就没有下一页了
if (res.data.data.list.length == 0) {
this.setData({
noMore: true
})
}
} else {
//返回失败
this.setData({
loadingFailed: true
})
}

})

},

})
更新于

请我喝[茶]~( ̄▽ ̄)~*

高祥 微信支付

微信支付

高祥 支付宝

支付宝

高祥 贝宝

贝宝