【问题标题】:VueJs - How can i know when the scroll bar of DIV reach its bottomVueJs - 我怎么知道 DIV 的滚动条何时到达底部
【发布时间】:2020-09-15 08:20:10
【问题描述】:

我是 Vuejs 的新手。当 Datatable vuejs 中的 div 到达其页面底部时,如何收到消息。当有人帮助我时,它会非常有帮助。

【问题讨论】:

  • 我尝试了这段代码,但是当它到达底部时仍然没有出错
  • 到目前为止你有什么尝试?

标签: vue.js vue-component vuetify.js


【解决方案1】:

我正在发布这个问题的答案,我得到了正确的答案。实际上,我从某人对这个问题的评论中得到了想法,我现在看不到。 添加代码:

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

【讨论】:

    猜你喜欢
    • 2013-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-04
    • 2017-06-26
    • 1970-01-01
    • 1970-01-01
    • 2014-12-12
    相关资源
    最近更新 更多