el-table通过tree-props实现表格嵌套表格

1475 ℃

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合并行的通用方法(附js代码)

el-table利用:row-style="rowClass"设置指定行变色

el-table表格显示selection多选时对某些复选框设置禁止选中

el-table表格实现多选功能(全选/指定选中/取消选中)

el-table实现拖拽行排序sortablejs

标签: el-table, 表格嵌套

上面是“el-table通过tree-props实现表格嵌套表格”的全面内容,想了解更多关于 vuejs 内容,请继续关注web建站教程。

当前网址:https://m.ipkd.cn/webs_1752.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

jQuery动态过渡删除元素height属性
帝国cms(EmpireCMS)网站管理系统7.5正式版免费下载
vue语法中关于watch和watchEffect的区别?
如何使用PHP百度翻译API实现西班牙语到俄语的翻译功能?
three.js绘制的八大行星运动效果