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

项目场景:

1:非懒加载的情况

1:效果展示


2:问题描述以及解决

1:图片展示

2:html 
<-- default-expand-all  代表默认展开 如果不展开删除就行 -->
<el-table
      ref="refsTable"
      v-loading="loading"
      :border="true"
      :data="tableData"
      style="width: 100%"
      row-key="billId"
      :header-cell-class-name="tableHeadStyle"
      :tree-props="{
        children: 'childList',
        hasChildren: 'undefined',
      }"
      :cell-class-name="cellStyle"
      :cell-style="{ textAlign: 'center' }"
      :header-cell-style="{ textAlign: 'center' }"
      default-expand-all
    >
    <el-table-column label="序号" width="120" prop="index">
      </el-table-column>
      <el-table-column label="项目编码" width="120" prop="">
        <template slot-scope="scope">
          <div class="" v-if="scope.row.parentId==null||
           scope.row.parentId==''">
            <el-input 
                v-model="scope.row.projectCode" 
                placeholder="请输入项目编码" />
          </div>
        </template>
      </el-table-column>
      <el-table-column label="项目名称" prop="billName"  min-width="140">
      </el-table-column>
      <el-table-column
        label="合同价"
        width="120"
        style="background: #b4de7a"
      >
        <el-table-column label="工程量">
          <el-table-column label="单位" prop="unitQuantities">
          </el-table-column>
          <el-table-column label="数量" prop="quantities">
          </el-table-column>
          <el-table-column label="单价" prop="billQuantities" fixed="right">
          </el-table-column>
        </el-table-column>
        <el-table-column label="工作量(万元)" prop="amountWork">
        </el-table-column>
      </el-table-column>
</el-table>
3:获取数据函数
// 获取表格基本数据
    getTableData(){
      this.loading=true;
      getBillWorks({
        lineName: this.$route.query.lineName,
        segmentName: this.$route.query.segmentName,
        lineId: this.$route.query.lineId,
        segmentId: this.$route.query.segmentId,
        segmentBillName: this.$route.query.segmentBillName,
        lineSegmentName: this.$route.query.lineSegmentName
      }) .then((res) => {
        this.loading=false;
        this.tableData=res.data.data;
      }).catch(err=>{
        console.log(err)
      })
    },

2:懒加载的情况

1:效果展示:


2:问题描述以及解决

1:图片展示

2:html 
<el-table
      ref="refsTable"
      v-loading="loading"
      :border="true"
      :data="tableData"
      style="width: 100%"
      row-key="billId"
      :header-cell-class-name="tableHeadStyle"
      :tree-props="{
        children: 'childList',
        hasChildren: 'hasChildren',
      }"
      :cell-class-name="cellStyle"
      :cell-style="{ textAlign: 'center' }"
      :header-cell-style="{ textAlign: 'center' }"
      lazy
      :load="loadChildData"
    >
    <el-table-column label="序号" width="120" prop="index">
      </el-table-column>
      <el-table-column label="项目编码" width="120" prop="">
        <template slot-scope="scope">
          <div class="" v-if="scope.row.parentId==null||
           scope.row.parentId==''">
            <el-input 
                v-model="scope.row.projectCode" 
                placeholder="请输入项目编码" />
          </div>
        </template>
      </el-table-column>
      <el-table-column label="项目名称" prop="billName"  min-width="140">
      </el-table-column>
      <el-table-column
        label="合同价"
        width="120"
        style="background: #b4de7a"
      >
        <el-table-column label="工程量">
          <el-table-column label="单位" prop="unitQuantities">
          </el-table-column>
          <el-table-column label="数量" prop="quantities">
          </el-table-column>
          <el-table-column label="单价" prop="billQuantities" fixed="right">
          </el-table-column>
        </el-table-column>
        <el-table-column label="工作量(万元)" prop="amountWork">
        </el-table-column>
      </el-table-column>
</el-table>
3:获取数据与子项数据函数
// 获取表格基本数据
    getTableData(){
      this.loading=true;
      getBillWorks({
        lineName: this.$route.query.lineName,
        segmentName: this.$route.query.segmentName,
        lineId: this.$route.query.lineId,
        segmentId: this.$route.query.segmentId,
        segmentBillName: this.$route.query.segmentBillName,
        lineSegmentName: this.$route.query.lineSegmentName
      }) .then((res) => {
        this.loading=false;
        this.tableData=res.data.data;
      }).catch(err=>{
        console.log(err)
      })
    },
    // 表格子项数据
    loadChildData(row, treeNode, resolve) {
      getBillWorks({
        segmentId: this.$route.query.segmentId,
        idPath:row.idPath
      }).then((res) => {
        resolve(res.data.data)
      }).catch(err => {
        console.log(err)
      })
    },

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值