<tempate里面使用
<uni-load-more v-if="load == 1" :loadingType="loadingType" :contentText="contentText"></uni-load-more>
<script里面导入
import uniLoadMore from '../../../components/uni-load-more.vue';
components: {
uniLoadMore
},
//data里面定义
loadingText: '加载中...',
loadingType: 0,
contentText: {
contentdown: '上拉显示更多',
contentrefresh: '正在加载...',
contentnomore: '没有更多数据了'
},
load: 0,
page: 1,
timer:{},
// 上拉加载
onReachBottom(){
if (this.timer != null) {
clearTimeout(this.timer)
}
this.timer = setTimeout(()=> {
this.getmorenews()
}, 1000);
},
接下来是method里面
//第一页
setAjax(){
uni.request({
url: 'https://******.com/Api/CommisionLog/index?p=' + this.page,
method: 'POST',
data:{
user_id: this.user_id,
search: this.search
},
header:{'Content-Type':'application/x-www-form-urlencoded'},
success: res => {
uni.hideLoading()
this.res = res.data.data.data.list
console.log(this.res)
},
fail: () => {},
complete: () => {}
});
},
// 加载更多
getmorenews() {
this.page++;//每触底一次 page +1
if (this.loadingType !== 0) {//loadingType!=0;直接返回
return false;
}
this.loadingType = 1;
uni.showNavigationBarLoading();//显示加载动画
uni.request({
url: 'https://************.com/Api/CommisionLog/index?p=' + this.page,
method: 'POST',
data:{
user_id: this.user_id,
search: this.search
},
header:{'Content-Type':'application/x-www-form-urlencoded'},
success: res => {
uni.hideLoading()
if (res.data.data.data.list == '') {//没有数据
this.loadingType = 2;
uni.hideNavigationBarLoading();//关闭加载动画
return;
}
this.res = this.res.concat(res.data.data.data.list);//将数据拼接在一起
this.loadingType = 0;//将loadingType归0重置
uni.hideNavigationBarLoading();//关闭加载动画
},
fail: () => {},
complete: () => {}
});
},
亲测有效