【发布时间】:2020-09-15 08:20:10
【问题描述】:
【问题讨论】:
-
我尝试了这段代码,但是当它到达底部时仍然没有出错
-
到目前为止你有什么尝试?
标签: vue.js vue-component vuetify.js
【问题讨论】:
标签: vue.js vue-component vuetify.js
我正在发布这个问题的答案,我得到了正确的答案。实际上,我从某人对这个问题的评论中得到了想法,我现在看不到。 添加代码:
mounted() {
let box = document.querySelector(".v-data-table__wrapper");
// @ts-ignore
box.addEventListener("scroll", this.scrollHandler);
}
/*
* Infinite scroll event
*/
scrollHandler(e) {
// @ts-ignore
let context = this.$store.state[this.$options.parent.fileName];
if (!context.lazyLoading.enabled) {
return;
}
let el = e.srcElement;
// @ts-ignore
this.reachedBottom = false;
// @ts-ignore
let context = this.$store.state[this.$options.parent.fileName];
// @ts-ignore
if (!this.reachedBottom) {
if (el.scrollTop >= (el.scrollHeight - el.clientHeight) - 100) {
// @ts-ignore
this.reachedBottom = true;
if (context.lazyLoading.enabled && context.lazyRecords && context.lazyRecords.length > 0)
context.formData = context.lazyRecords.slice(0, (context.formData.length + (context.lazyLoading.initialRecordLoad || context.dashboard.lazyLoading.initialRecordLoad)));
else if (!context.lazyLoading.enabled)
context.formData = context.copyData.slice(0, (context.formData.length + (context.lazyLoading.initialRecordLoad || context.dashboard.lazyLoading.initialRecordLoad)));
}
}
this.$nextTick(() => {
// @ts-ignore
this.reachedBottom = false;
});
}
【讨论】: