vue(element ui )el-table树形表格展示及数据对齐

el-table树形结构列表展示及数据不对齐问题解决

效果图

在这里插入图片描述

后端返回数据结构

在这里插入图片描述

页面代码

 <el-table class="sysDictInfoTable" :data="tableData" height="380" style="width: 100%;" row-key="nodeId"
        :tree-props="{ children: 'relatedPartyChild', hasChildren: 'hasChildren' }">
        <el-table-column prop="relatedname" label="名称"> </el-table-column>
        <el-table-column prop="idTypeName" label="证件类型"> </el-table-column>
        <el-table-column prop="identityNo" label="证件号码"> </el-table-column>
        <el-table-column label="操作" width="250" fixed="right">
          <template #default="scope">
            <el-button type="primary" size="small" @click="ModifyTable(scope.row)">修改</el-button>
          </template>
        </el-table-column>
      </el-table>
<script>
export default {
    
    
  data () {
    
    
    return {
    
    
      tableData: [],
    };
  },
  mounted () {
    
    
    this.search();
  },
  methods: {
    
    
    //查询
    search () {
    
    
      let formData = {
    
    
        parentcode: '0'
      }
      affiliatedQuery_tree(formData).then((res) => {
    
    
      //接口返回列表
        this.tableData = res.data;
      }).catch(() => {
    
    
        this.tableData = [];
      });
    },
    //修改
    ModifyTable(){
    
    }
  },
};
</script>

<style scoped lang='scss'>
// el-table表格对齐
.sysDictInfoTable ::v-deep .el-table__row:not([class*="el-table__row--level-"]) {
    
    
  td:first-child {
    
    
    padding-left: 24px !important;    //一级数据无Child缩进
  }
}
.sysDictInfoTable ::v-deep  .el-table__placeholder{
    
    
    margin-left: 3px;        //子节点无Child缩进
}
</style>

注意点:
el-table配置里row-key必须是唯一性
:tree-props=“{ children: ‘relatedPartyChild’, hasChildren: ‘hasChildren’ }” children配置为后端返回的节点字段即可

猜你喜欢

转载自blog.csdn.net/wangjiecsdn/article/details/127410823