• element-ui中表格树类型数据的显示


    项目场景:

    1:非懒加载的情况

    1:效果展示


    2:问题描述以及解决

    1:图片展示

    2:html 
    1. <-- default-expand-all 代表默认展开 如果不展开删除就行 -->
    2. ref="refsTable"
    3. v-loading="loading"
    4. :border="true"
    5. :data="tableData"
    6. style="width: 100%"
    7. row-key="billId"
    8. :header-cell-class-name="tableHeadStyle"
    9. :tree-props="{
    10. children: 'childList',
    11. hasChildren: 'undefined',
    12. }"
    13. :cell-class-name="cellStyle"
    14. :cell-style="{ textAlign: 'center' }"
    15. :header-cell-style="{ textAlign: 'center' }"
    16. default-expand-all
    17. >
    18. "序号" width="120" prop="index">
    19. "项目编码" width="120" prop="">
    20. "项目名称" prop="billName" min-width="140">
    21. label="合同价"
    22. width="120"
    23. style="background: #b4de7a"
    24. >
    25. "工程量">
    26. "单位" prop="unitQuantities">
    27. "数量" prop="quantities">
    28. "单价" prop="billQuantities" fixed="right">
    29. "工作量(万元)" prop="amountWork">
    3:获取数据函数
    1. // 获取表格基本数据
    2. getTableData(){
    3. this.loading=true;
    4. getBillWorks({
    5. lineName: this.$route.query.lineName,
    6. segmentName: this.$route.query.segmentName,
    7. lineId: this.$route.query.lineId,
    8. segmentId: this.$route.query.segmentId,
    9. segmentBillName: this.$route.query.segmentBillName,
    10. lineSegmentName: this.$route.query.lineSegmentName
    11. }) .then((res) => {
    12. this.loading=false;
    13. this.tableData=res.data.data;
    14. }).catch(err=>{
    15. console.log(err)
    16. })
    17. },

    2:懒加载的情况

    1:效果展示:


    2:问题描述以及解决

    1:图片展示

    2:html 
    1. <el-table
    2. ref="refsTable"
    3. v-loading="loading"
    4. :border="true"
    5. :data="tableData"
    6. style="width: 100%"
    7. row-key="billId"
    8. :header-cell-class-name="tableHeadStyle"
    9. :tree-props="{
    10. children: 'childList',
    11. hasChildren: 'hasChildren',
    12. }"
    13. :cell-class-name="cellStyle"
    14. :cell-style="{ textAlign: 'center' }"
    15. :header-cell-style="{ textAlign: 'center' }"
    16. lazy
    17. :load="loadChildData"
    18. >
    19. <el-table-column label="序号" width="120" prop="index">
    20. el-table-column>
    21. <el-table-column label="项目编码" width="120" prop="">
    22. <template slot-scope="scope">
    23. <div class="" v-if="scope.row.parentId==null||
    24. scope.row.parentId==''">
    25. <el-input
    26. v-model="scope.row.projectCode"
    27. placeholder="请输入项目编码" />
    28. div>
    29. template>
    30. el-table-column>
    31. <el-table-column label="项目名称" prop="billName" min-width="140">
    32. el-table-column>
    33. <el-table-column
    34. label="合同价"
    35. width="120"
    36. style="background: #b4de7a"
    37. >
    38. <el-table-column label="工程量">
    39. <el-table-column label="单位" prop="unitQuantities">
    40. el-table-column>
    41. <el-table-column label="数量" prop="quantities">
    42. el-table-column>
    43. <el-table-column label="单价" prop="billQuantities" fixed="right">
    44. el-table-column>
    45. el-table-column>
    46. <el-table-column label="工作量(万元)" prop="amountWork">
    47. el-table-column>
    48. el-table-column>
    49. el-table>
    3:获取数据与子项数据函数
    1. // 获取表格基本数据
    2. getTableData(){
    3. this.loading=true;
    4. getBillWorks({
    5. lineName: this.$route.query.lineName,
    6. segmentName: this.$route.query.segmentName,
    7. lineId: this.$route.query.lineId,
    8. segmentId: this.$route.query.segmentId,
    9. segmentBillName: this.$route.query.segmentBillName,
    10. lineSegmentName: this.$route.query.lineSegmentName
    11. }) .then((res) => {
    12. this.loading=false;
    13. this.tableData=res.data.data;
    14. }).catch(err=>{
    15. console.log(err)
    16. })
    17. },
    18. // 表格子项数据
    19. loadChildData(row, treeNode, resolve) {
    20. getBillWorks({
    21. segmentId: this.$route.query.segmentId,
    22. idPath:row.idPath
    23. }).then((res) => {
    24. resolve(res.data.data)
    25. }).catch(err => {
    26. console.log(err)
    27. })
    28. },

  • 相关阅读:
    比较 内核 读写锁与顺序锁, RCU
    使用Python编写高效程序
    大结局!OpenAI创始人奥特曼和 Greg Brockman 将加入微软!!!
    NTU 课程笔记:向量和矩阵
    数据分类分级指南范围
    OA项目之我的审批(查询&会议签字)
    4D毫米波雷达加速向上,搭载福瑞泰克解决方案量产车型预计年底上市
    大数据应用概览(林子雨慕课课程)
    【二十三】springboot整合spring事务详解以及实战
    Redis字典实现
  • 原文地址:https://blog.csdn.net/m0_63026408/article/details/133902291