丸子2021-07-08 15:07:19点赞:0阅读:93
关注
<van-pull-refresh
v-model="isLoading"
success-text="刷新成功"
@refresh="onRefresh"
>
<van-list
v-model="loading"
:finished="finished"
:finished-text="finishedText"
@load="onLoad"
>
<div class="cell" v-for="(item,index) in list" :key="index">
……
</div>
</van-list>
</van-pull-refresh>
data() {
return {
page: 1,
page_size:10,
list: [],
loading: false,
finished: false,
finishedText: "",
isLoading:false,
};
},
methods: {
onLoad(){
api.poctList({page:this.page}).then((res) => {
if (res.code === 200) {
this.list = this.list.concat(res.data);
this.loading = false;
this.isLoading = false;
let pageNum = Math.ceil(res.total / this.page_size);
if (this.page >= pageNum) {
// 数据全部加载完成
this.finished = true;
}
this.list.length === 0 ? (this.finishedText = "暂无数据") : (this.finishedText = "没有更多了");
this.page++;
}else{
this.finished = true;
this.loading = false;
}
});
},
onRefresh(){
this.page = 1;
this.list = [];
this.loading = true;
this.isLoading = true;
this.finished = false;
this.finishedText = "";
this.onLoad();
},
}