uniapp开发时,常常需要进行底部监听,用来加载分页数据 使用onReachBottom判断页面是否触底,用来进行新数据加载
onReachBottom() {
this.getmore();
},
getmore() {
var that = this;
that.page = that.page + 1;
uni.showNavigationBarLoading();
that.more = 'loading';
let data = {
page: this.page,
catId: this.catId,
keyword: this.keyword,
};
this.$minApi
.infolists(data)
.then(res => {
uni.hideNavigationBarLoading();
console.log(res);
that.more = 'more';
if (res.code == 1) {
var data = res.data.rows;
if (!data || data.length == 0) {
that.more = 'noMore';
}
for (var i = 0; i < data.length; i++) {
that.list.push(data[i]);
}
} else {
uni.showToast({
title: res.msg,
duration: 2000,
icon: 'none'
});
}
})
.catch(err => {
console.log(err);
});
},
getlist() {
var that = this;
this.page = 1;
let data = {
page: this.page,
catId: this.catId,
keyword: this.keyword,
};
uni.showNavigationBarLoading();
this.$minApi.infolists(data).then(res => {
uni.hideNavigationBarLoading();
console.log(res);
if (res.code == 1) {
this.list = res.data
} else {
uni.showToast({
title: res.msg,
icon: 'none',
duration: 2000
});
}
});
},