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前端知识点offset,scroll,client,冒泡,事件对象的应用整理总结 2024-01-06
- Ajax与mysql数据交互制作留言板功能(全) 2023-01-31
- 用ajax实现预览链接可以看到链接的内容 2024-02-07
- 微信小程序页面间跳转传参方式总结 2024-03-08
- JS写XSS cookie stealer来窃取密码的步骤详解 2024-01-29
- Vue_vue_demo、v-model与v-on事件 2023-10-08
- ajax实现select三级联动效果 2023-02-14
- 魔兽世界火法神器故事全面介绍_wow火法神器获得方法推荐 2024-01-23
- 浅析location.href跨窗口调用函数 2024-01-08
- js实现文字选中分享功能 2023-12-22