0


element table数据量太大导致网页卡死崩溃

做后台项目时,一次性在表格中加载几百上千条数据,发现有时页面会崩溃。究其原因,发现是一次渲染dom太多导致卡顿。

在此尝试了多种解决方法,发现最优的就是替换组件,elementUI中的表格组件el-table性能不优,数据量大的时候,尤其是可操作表格,及其容易卡顿。在这里介绍一个新的第三方插件:unmy-ui。

官网会有具体的操作介绍和相关API http://www.umyui.com/umycomponent/uxGridApi

1.安装

  1. npm install umy-ui

2.引入

在main.js中写入以下内容:

  1. import Vue from 'vue';
  2. import UmyUi from 'umy-ui'
  3. import 'umy-ui/lib/theme-chalk/index.css';// 引入样式
  4. import App from './App.vue';
  5. Vue.use(UmyUi);
  6. new Vue({
  7. el: '#app',
  8. render: h => h(App)
  9. });

3.在需要的页面写入表格(仅展示关键代码,可根据自己需求添加)

  1. <ux-grid
  2. border
  3. keep-source
  4. ref="plTable"
  5. show-summary
  6. :data="form.itemList"
  7. :edit-config="{ trigger: 'click', mode: 'cell' }"
  8. max-height="432"
  9. >
  10. <ux-table-column field="category" title="类别" width="120">
  11. <template slot-scope="scope">
  12. <el-select
  13. size="mini"
  14. v-model="scope.row.category"
  15. @change="changeCategory(scope.row.category, scope.rowIndex)"
  16. >
  17. <el-option
  18. v-for="(item, index) in categoryGroup"
  19. :key="index"
  20. :value="item.value"
  21. :label="item.label"
  22. >{{ item.label }}</el-option
  23. >
  24. </el-select>
  25. </template>
  26. </ux-table-column>
  27. </ux-grid>

在此解释我写项目时遇到和el-table不同的两点:

  • el-table 中绑定数据的prop和ux-grid中的field对应,label和title对应;

  • change事件中传递该行的索引,el-table中用scope.$index,在ux-grid中用scope.rowIndex;

最后解决页面卡顿崩溃的问题。

如有问题,欢迎指正!!!


本文转载自: https://blog.csdn.net/weixin_50606255/article/details/128654732
版权归原作者 Apeng_0919 所有, 如有侵权,请联系我们删除。

“element table数据量太大导致网页卡死崩溃”的评论:

还没有评论