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实现表格嵌套表格
基础教程推荐
猜你喜欢
- js实现的在本地预览图片功能示例 2023-12-14
- jquery实现滑动楼梯效果 2024-01-17
- 常见的浏览器存储方式(cookie、localStorage、sessionStorage) 2024-02-10
- webpack里使用jquery.mCustomScrollbar插件的方法 2024-01-17
- 用ul li实现边框重合并附带鼠标经过效果 2024-01-09
- 利用JS生成博文目录及CSS定制博客 2024-01-17
- 纯css实现输入框placeholder动效及输入校验 2024-01-17
- 浅谈CSS3鼠标移入图片动态提示效果(transform) 2023-12-21
- Firebug入门指南(Firefox浏览器) 2024-01-16
- 四步轻松实现ajax发送异步请求 2023-02-14
