1、html代码如下:
<el-table>
:data="tableData"
style="width: 100%;margin-bottom: 20px;"
row-key="id"
border
default-expand-all
:tree-props="{children: 'children', hasChildren: 'hasChildren'}">
<el-table-column
prop="date"
label="日期"
sortable
width="180">
</el-table-column>
<el-table-column
prop="name"
label="姓名"
sortable
width="180">
</el-table-column>
<el-table-column
prop="address"
label="地址">
</el-table-column>
</el-table>
//这里有2点需要注意:
1、row-key="id";
2、:tree-props="{children: 'children', hasChildren: 'hasChildren'}"。
2、js代码:
export default {
data() {
return {
tableData: [{
id: 1,
date: '2016-05-02',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄'
}, {
id: 2,
date: '2016-05-04',
name: '王小虎',
address: '上海市普陀区金沙江路 1517 弄'
}, {
id: 3,
date: '2016-05-01',
name: '王小虎',
address: '上海市普陀区金沙江路 1519 弄',
children: [{
id: 31,
date: '2016-05-01',
name: '王小虎',
address: '上海市普陀区金沙江路 1519 弄'
}, {
id: 32,
date: '2016-05-01',
name: '王小虎',
address: '上海市普陀区金沙江路 1519 弄'
}]
}]
}
}
}
//注意children里面的id
总结:
1、el-table属性 row-key 一定要写。
2、如果children和hasChildren不是默认则需要指定 :tree-props=”{children:’children’, hasChildren:’hasChildren’}”
3、lazy为false时,数据不能包含hasChildren字段
沃梦达教程
本文标题为:el-table通过tree-props实现表格嵌套表格
猜你喜欢
- 模仿combox(select)控件,不用为美化select烦恼了。 2022-11-04
- JS实现清除指定cookies的方法 2024-01-14
- 利用JS生成博文目录及CSS定制博客 2024-02-21
- js原生appendChild的bug解决心得分享 2023-12-02
- 【VUE3.0体验】建路由,加入ElementUI3框架 2023-10-08
- 原生javascript实现读写CSS样式的方法详解 2024-02-22
- jQuery子属性过滤选择器用法分析 2024-02-24
- web前端性能优化之合理的优化网站图片可以带来更多的流量 2024-02-04
- 如果找不到,我们如何使用Apache重定向到新的HTML静态内容,并回退到基于CMS的旧PHP版本? (nginx try_files) 2023-10-25
- 纯CSS实现hover图片pop-out弹出效果的实例代码 2024-02-25