vue(element ui )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配置为后端返回的节点字段即可
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~