zoukankan      html  css  js  c++  java
  • vue + element table数据过多实现懒加载

      components: {
        CloseButton,
        Pagination,
        Tree,
        Dialog
      },
      directives: {
        loadmore: {
          bind (el, binding) {
            const selectWrap = el.querySelector('.el-table__body-wrapper')
            selectWrap.addEventListener('scroll', function () {
              const scrollDistance = this.scrollHeight - this.scrollTop - this.clientHeight
              // 判断是否到底,scrollTop为已滚动到元素上边界的像素数,scrollHeight为元素完整的高度,clientHeight为内容的可见宽度
              if (scrollDistance <= 10) {
                binding.value()
              }
            })
          }
        }
      },
    el-table.standard-table.management-table(
                      :data="tableData.data"
                      height="100%"
                      :ref="tableData.tableRef"
                      @select="handleCheckboxSelect"
                      @row-click="handleRowSelect"
                      v-loadmore='loadmore'
                    )
    methods: {
        // table滚动到底部触发该事件 loadNum: 0
        loadmore () {
          this.loadNum++
          this.tableData.data = [...this.tableData.data, ...this.listEach(this.loadNum)]
        },
        // 每次显示6条数据,滚动到底部数据加6
        listEach (Num) {
          const NumStart = ((Num - 1) * 5) + 6
          const NumEnd = (Num * 5) + 6
          const tableDataEach = this.listArray.slice(NumStart, NumEnd)
          return tableDataEach
        } //listArray是table获取的所有数据
        // 点击左侧的树结构获取对应的数据
        async handleNodeClick (event, treeId, treeNode) {
          const idArr = []
          const idResArr = this.findNodeChildren(treeNode, idArr)
          const ids = idResArr.join(',')
          this.ids = ids
          const parmas = {
            id: '',
            name: '',
            ids: ids
          }
          const data = await getListQualityDefectReq(parmas)
          if (!data) return
          if (data.success) {
            this.listArray = data.data
            this.loadNum = 0
            this.tableData.data = this.listArray.slice(0, 6)
          }
        },
    }

     参考: https://blog.csdn.net/qq_52912134/article/details/117958214

    https://segmentfault.com/a/1190000018756141?utm_source=tag-newest

  • 相关阅读:
    document.body.clientHeight 和 document.documentElement.clientHeight 的区别
    Javascript操作div及其内含对象示例
    面向对象分析设计的经验原则
    翻页控件示例代码
    C#的6种常用集合类示例
    UML基础知识
    重温OSI和TCP/IP网络分层
    设计模式总结
    活用设计模式
    GridView当数据源为空时仍显示表头
  • 原文地址:https://www.cnblogs.com/jvziking/p/15124511.html
Copyright © 2011-2022 走看看