• 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

  • 相关阅读:
    BNUOJ 34978 汉诺塔 (概率dp)
    hdu1427 速算24点
    vim学习之以退为进——可反复移动和可反复改动的美妙结合
    C++设计模式实现--策略(Strategy)模式
    ios怎样在一个UIImageButton的里面加一些自己定义的箭头
    HTML5 Canvas 画图入门
    AT3728 Squirrel Migration
    HTTP请求的GET与POST方式的区别
    HTTP 的请求过程?
    servlet的生命周期
  • 原文地址:https://www.cnblogs.com/jvziking/p/15124511.html
Copyright © 2020-2023  润新知