elementui实现表格树形列表加载教程,供大家参考,具体内容如下

element ui 是一套采用 vue 2.0 作为基础框架实现的组件库,一套为开发者、设计师和产品经理准备的基于 vue 2.0 的组件库,提供了配套设计资源,帮助网站快速成型

关键代码,在el-table添加属性, :tree-props=”{children: ‘children’}” ,注意row必须命名为children,官网也进行了说明:

支持树类型的数据的显示。当 row 中包含 children 字段时,被视为树形数据。渲染树形数据时,必须要指定 row-key。支持子节点数据异步加载。设置 table 的 lazy 属性为 true 与加载函数 load 。通过指定 row 中的 haschildren 字段来指定哪些行是包含子节点。children 与 haschildren 都可以通过 tree-props 配置。

<el-table
  ref="table"
  :data="appritemdata"
  :header-cell-style="headclass"
        @select="handleselection"
        row-key="approveitem"
        height="420"
  border
       default-expand-all
       :tree-props="{children: 'children'}">
 <el-table-column
   type="selection"
   width="55">
 </el-table-column>
 <el-table-column
   prop="itemcode"
   label="事项编码">
 </el-table-column>
 <el-table-column
   prop="approvename"
   label="事项名称">
 </el-table-column>
 <el-table-column
   prop="apprstatusstr"
   label="配置的环节"
   color="blue">
 </el-table-column>
</el-table>

后台json数据:

{
    "id":3,
    "itemcode":"123",
    "approvename":"测试事项",
    "apprstatusstr":"环节名称",
    "children":[
        {
            "id":31,
            "itemcode":"111",
            "approvename":"测试事项",
            "apprstatusstr":"环节名称"
        }
    ]
}
<script type="text/babel">
       var vm = new vue({
           el: '#app',
           data:{
               appritemdata : [],
               currentpage: 1,  //当前页
               totalrow: 0, //总页数
               pagesize: 10 //当前显示条数
           },
           computed: {},
           watch: {},
           created() {},
           mounted() {
               this.loaditemdata();
  },
           methods: {
               // 加载事项信息
   loaditemdata () {
                   var pagesize = this.pagesize;
                   var currentpage = this.currentpage;
                   console.log("pagesize:"+pagesize+",currentpage:"+currentpage);
       //debugger;
       var geturl = '${root}/config/loaditemdata.do?rows='+pagesize + '&page=' + currentpage;
                   $.ajax({
                       type: 'get',
                       url:geturl,
                       contenttype: "application/json; charset=utf-8",
                       success: function(data) {
                           //debugger;
                           console.log("totalrow:"+data.total);
                           vm.appritemdata = data.rows;
                       },
                       error: function(e) {
                           console.log("更新数据出现错误:",e);
                       }
                   })
               }
           }
       });
</script>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持www.887551.com。