关注

vant分页、下拉刷新

<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();
},
}


文章分类前端

评论

赞0

评论列表

微信小程序
QQ小程序

关于作者

点赞数:0
关注数:0
粉丝:1
文章:4
关注标签:0
加入于:2020-07-21