场景

有需求,使用懒加载的展开列,当加载的数据量过大,如大于1000条以上,浏览器可能卡死挂了

分析

大量的dom的渲染绘制,导致了浏览器处理不过来

解决

虚拟列表

vue-table 虚拟列表的使用

vue-table官网

<vxe-table border resizable height="100%" ref="xTree" row-id="rid" class="mytable-style"
                :row-class-name="rowBackgroundColor" :key="JSON.stringify(columnList)"
                :row-config="{keyField:'rid'}" show-overflow="tooltip"
                :tree-config="{reserve:true,accordion:true,lazy: true, transform: true, rowField: 'rid', parentField: 'parentId', hasChild: 'haveMultiplePrice', loadMethod: loadChildren}"
                :data="tableData" :scroll-y="{enabled: true,gt:20}" @checkbox-change="selectChangeEvent" @checkbox-all="selectChangeEvent">
                <vxe-column type="checkbox" width="40" fixed="left" align="center"></vxe-column>
                <vxe-column width="72" fixed="left" title="状态" align="right" tree-node :show-overflow="false">
                  <template #default="{ row }">
                    <el-tooltip class="item" effect="dark" :content="'方案 : ' + row.monitorNames"
                      placement="right-start">
                      <i class="el-icon-bell" v-show="row.monitor == 1"></i>
                    </el-tooltip>
                    <el-tooltip class="item" effect="dark" content="提示" placement="right-start">
                      <i class="el-icon-view" v-show="row.popup == 1"></i>
                    </el-tooltip>
                   <span style="opacity: 0;width: 0;display: inline-block;">.</span>
                  </template>
                </vxe-column>
                <vxe-column :field="item.prop" :title="item.label" show-overflow :width="item.width"
                  :header-align="item.align" :align="item.align" v-for="item in columnList" :key="item.prop"
                  :fixed="['scode','sname'].includes(item.prop)?'left':''" :visible="item.visible">
                  <template slot="header">
                    <span slot="reference" title="优先" v-if="item.prop === 'limitLeft'">{{
                        item.label
                    }}<i class="el-icon-question c-blue f14"></i>
                    </span>
                    <div v-else>{{ item.label }}</div>
                  </template>
                </vxe-column>
</vxe-table>

	selectChangeEvent ({ checked }) {
      this.multipleSelection = this.$refs.xTree.getCheckboxRecords()
    },

    rowBackgroundColor ({ row, rowIndex }) {
      if (row.stop == 0) {
        return 'row-ccc'
      } else if (row.qualify == 1) {
        return 'row-red'
      }
      return null
    },
    getColumnData (list) {
      this.columnList = list;
    },
    loadChildren ({ row }) {
      // row.parentId = row.rid
      return new Promise(resolve => {
        loadChild({ ldate: row.ldate, scode: row.scode, rid: row.rid }).then(res => {
          if (res.code === 0) {
            resolve(res.data.map(item => ({
              ...item,
              parentId: row.rid,
            })))
          } else {
            resolve([])
          }
        })

      })
    },
GitHub 加速计划 / vu / vue
207.54 K
33.66 K
下载
vuejs/vue: 是一个用于构建用户界面的 JavaScript 框架,具有简洁的语法和丰富的组件库,可以用于开发单页面应用程序和多页面应用程序。
最近提交(Master分支:2 个月前 )
73486cb5 * chore: fix link broken Signed-off-by: snoppy <michaleli@foxmail.com> * Update packages/template-compiler/README.md [skip ci] --------- Signed-off-by: snoppy <michaleli@foxmail.com> Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com> 4 个月前
e428d891 Updated Browser Compatibility reference. The previous currently returns HTTP 404. 5 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐