如图,第一次进入页面时,没有数据的情况下应该显示没有更多才对,但是现在是一直显示加载中,除非进行一次上拉动作,才会显示没有更多数据,这个问题怎么解决?
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>
components(js代码):
Component({
/**
* 组件的属性列表
*/
properties: {
loadingtext:{
type:String,
value:"正在加载中..."
},
loadedtext:{
type:String,
value:"没有更多数据"
},
hasmore:{
type:Boolean,
value:true
},
height:{
type:Number,
value:40
}
},
})
index(wxml代码):
<loadingmore hasmore="{{hasmore}}"></loadingmore>
index(js代码):
data: {
hasmore: true,
wehicles: [],
},
lowdrelease(start = 0) {
const that = this;
let promise = db.collection("wehicle");
if (start > 0) {
promise = promise.skip(start);
}
promise.limit(10).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;
}
// console.log(wehicles);
newWehicles.forEach((wehicle, index) => {
wehicle.create_time = wehicle.create_time.toString();
})
that.setData({
wehicles: newWehicles,
hasmore: hasmore
})
})
},
onReachBottom() {
this.lowdrelease(this.data.wehicles.length);
},
自己在代码中判断啊,要是没有数据,之间拦截上拉了