当第一次或者刷新页面,也没执行上拉加载的时候,一直显示正在加载中,如图:正常情况下应该是当没有数据或者不足以到上拉加载的时候,应该显示没有更多数据,有上拉加载的动作时才显示正在加载中
components组件代码
wxml代码:
<button class="loading-btn" loading="{{hasmore}}" style="height:{{height}}px;">
<block wx:if="{{hasmore}}">
<text class="loadingtext">{{loadingtext}}</text>
</block>
<block wx:else>
<text class="loadingtext">{{loadedtext}}</text>
</block>
</button>
js代码:
properties: {
loadingtext:{
type:String,
value:"正在加载中..."
},
loadedtext:{
type:String,
value:"没有更多数据"
},
hasmore:{
type:Boolean,
value:true
},
height:{
type:Number,
value:40
},
},
pages页面index代码:
wxml代码:
<loadingmore hasmore="{{hasmore}}"></loadingmore>
js代码:
const db = wx.cloud.database();
Page({
/**
* 页面的初始数据
*/
data: {
items: ["全部", "我要找车", "我要找人", "我找货车", "我要找货"],
hasmore: true,
wehicles: [],
result: 0,
startPoint:'',
goal: '',
isQuerying: false,
list:[],
listones:[],
listtwos:[],
listthrees:[],
listfours:[],
},
/**
* 获取数据库数据
*/
lowdrelease(start = 0) {
const that = this;
let list = db.collection("wehicle");
if (start > 0) {
list = list.skip(start);
}
list.limit(5).orderBy("create_time", "desc").get().then(res => {
console.log(res);
const wehicles = res.data;
let hasmore = true
if (wehicles.length == 0) {
hasmore = false
}
let newWehicles = [];
if (start > 0) {
newWehicles = that.data.wehicles.concat(wehicles);
} else {
newWehicles = wehicles;
}
newWehicles.forEach((wehicle, index) => {
wehicle.create_time = wehicle.create_time.toString();
})
that.setData({
wehicles: newWehicles,
hasmore: hasmore,
})
});
list.count().then(res => {
console.log(res)
that.setData({
result:res.total
})
})
/**
* 生命周期函数--监听页面显示
*/
onShow() {
this.lowdrelease(0);
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
this.lowdrelease(0);
this.setData({
isQuerying:false
})
wx.stopPullDownRefresh();
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
if(!this.data.isQuerying) {
this.lowdrelease(this.data.wehicles.length);
}else{
this.data.isQuerying
}
},