现在data return中定义好需要得变量
currentPage是当前第几页,默认为第一页
hasMore用来判断下一页是否还有值需要加载
// 当前页码
currentPage: 1,
hasMore: true,
onReachBottom和methods同级
这里我是使用了base64加密,如果你的不需要加密,直接在请求中定义data,发起请求就可以了。第一个为加密写法,第二个不加密写法。
加密:
onReachBottom() {
// 首先要判断是否还要继续加载
if (!this.hasMore) {
return
}
// 开始发起请求
let datasss = {
page: this.currentPage,
}
uni.request({
url: 'xxxxxxx',//接口地址
method: 'POST',
success: (res) => {
let vm = this
// 得到数据后,先判断是否hasMore
if (res.data.data.data.length < 10) {
vm.hasMore = false;
}
this.currentPage++
this.cpDD = this.cpDD.concat(res.data.data.data); //拼接数据
},
data: {
params: base64.encode(JSON.stringify(datasss)) //base64加密写法
},
});
},
不加密:
onReachBottom() {
// 首先要判断是否还要继续加载
if (!this.hasMore) {
return
}
uni.request({
url: this.YM + '/api/order/orderList',
method: 'POST',
header: {
'Content-Type': 'application/json;charset=UTF-8',
},
data: {
page: this.currentPage,
},
success: (res) => {
let vm = this
// 得到数据后,先判断是否hasMore
if (res.data.data.data.length < 10) {
vm.hasMore = false;
}
this.currentPage++
this.cpDD = this.cpDD.concat(res.data.data.data);
},
});
},
如果你的业务需求中有tabs切换这些,在切换时记得将this.currentPage的初始值设置为第一页