前言
<van-list v-model="loading" @load="initTodoList" :finished="isLoadFinished" :offset="getListMoreOffset">
写了个瀑布式分页,调用时多次,预期是两次,而且第二次开始,请求参数一致
原因
非加载中,loading
为false
,此时会根据列表滚动位置判断是否触发onload事件(列表内容不足一屏幕时,会直接触发)
加载中,loading
为true
,表示正在发送异步请求,此时不会触发onload事件
解决
加载中应该设置为false
,其次,达到最大条数时,isLoadFinished
要设置为true
this.loading = true;
queryMyToDoListByTerm(this.queryParam).then(response => {
if (response.code === 200) {
//自查分页
if (this.type == '2') {
//关闭
this.loading = false;
//追加数组
this.todoList = this.todoList.concat(response.data.list);
if ((this.queryParam.num*10) >= response.data.total) {
this.isLoadFinished = true;
} else {
this.queryParam.num++;
}
// this.listActive = true;
console.log("this.queryParam", this.isLoadFinished, this.queryParam.num,response.data.total )
} else {
this.todoList = response.data.list;
this.isLoadFinished = true;
}
}
});