vue 滚动到底部分页

  mounted () {
    // 监听滚动
    this.dom = document.querySelector('.mb-list-scorll')
    this.dom.addEventListener('scroll', this.scrollFn)
  },
  beforeDestroy () {
    // 移除监听
    this.dom.removeEventListener('scroll', this.scrollFn)
  },
    // 滚动分页
    scrollFn () {
      const scrollDistance =
        this.dom.scrollHeight - this.dom.scrollTop - this.dom.clientHeight
      const scrollTop = this.dom.scrollHeight
      if (scrollDistance <= 0) {
        console.log('到底啦!!!')
        // 加载内容
        setTimeout(() => {
          if (this.dataList.length < this.count) {
            this.page++
            this.getList()
            this.dom.scrollTop = scrollTop
          } else {
          }
        }, 300)
      }
    },
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容