vant-list @load加载 不断请求接口问题个人解决方案
- 在vant-list 标签中配置offset属性,默认值300太大了(建议在30左右) ;
- 有配置van-pull-refresh使用的, 在vant-list 中 设置 :immediate-check="false"
- 设定一个变量,例如:isLoad,在每次请求方法时拦截多余的请求
async pageMore() {
if (!this.isLoad) {
this.isLoad = true;
this.loadStart();
await this.$postData("xxx", this.queryParam, {}).then((res) => {
if (res.status === 200) {
res.data.records.forEach(v => {
this.dataList.push(v);
});
const list = res.data.records;
if (list === null || list.length === 0 ||
this.queryParam.size * this.queryParam.current >= res.data.total
|| this.dataList.length >= res.data.total) {
this.finished = true;
}
this.queryParam.current++;
} else {
this.$toast.fail(res.msg);
}
}).catch(e => {
this.$toast.fail(e.message);
}).finally(() => {
// this.refreshing = false;
this.loadEnd();
this.isLoad = false;
});
}
}
目前没找到和想到更好的方案,有哪位朋友有更好的方案,请评论区说一下哈。