vue+element-ui动态生成多级表头的方法


Posted in Javascript onAugust 28, 2018

vue+element

html配置:

<div id="table">{{tableData}}
<el-table :data="tabledata01" :span-method="tableSpanMethod" max-height="420">
<el-table-column v-for='item in tableConfig' :label="item.label" :prop='item.prop' :width='item.width' :key="item.id">
<el-table-column v-if='item.children||item.children.length>0' v-for="item1 in item.children"
:label="item1.label" :prop='item1.prop' :width='item1.width' :key="item1.id">
<el-table-column v-if='item1.children||item1.children.length>0' v-for="item2 in item1.children"
:label="item2.label" :prop='item2.prop' :width='item2.width' :key="item2.id">
</el-table-column>
</el-table-column>
</el-table-column>
</el-table>
</div>

data:

tableConfig:[
{id:100,label:'一级表头',prop:'',width:'',children:[
{id:110,label:'二级表头1',prop:'districtName',width:''},
{id:120,label:'二级表头2',prop:'timeDimension',width:''}
]},
{id:200,label:'一级表头',prop:'',width:'',children:[
{id:210,label:'二级表头',prop:'',width:'',children:[
{id:211,label:'三级表头',prop:'residentPopNum',width:'110'},
{id:212,label:'三级表头',prop:'residentPopDst',width:'110'}
]}
]},
{id:300,label:'一级表头',prop:'',width:'',children:[
{id:310,label:'二级表头',prop:'',width:'',children:[
{id:311,label:'三级表头',prop:'liveLandArea',width:'110'},
{id:312,label:'三级表头',prop:'liveLandDst',width:'110'}
],
},
{id:320,label:'二级表头',prop:'',width:'',children:[
{id:321,label:'三级表头(km²)',prop:'employmentLandArea',width:'110'},
{id:322,label:'三级表头',prop:'employmentLandDst',width:'110'}
],
}
]},
{id:400,label:'一级表头',prop:'',width:'',children:[
{id:410,label:'二级表头',prop:'',width:'',children:[
{id:411,label:'三级表头(个)',prop:'regionTrafficHubNum',width:'110'},
{id:412,label:'三级表头(人次/km²)',prop:'regionTrafficHubFlow',width:'140'}
],
},
{id:420,label:'二级表头',prop:'',width:'',children:[
{id:421,label:'三级表头(个)',prop:'highSpeedNum',width:'110'},
{id:422,label:'三级表头(个/km²)',prop:'highSpeedDst',width:'140'}
],
},{id:430,label:'二级表头',prop:'',width:'',children:[
{id:431,label:'三级表头(个)',prop:'trackTrafficSpotNum',width:'140'},
{id:432,label:'三级表头(个/km²)',prop:'trackTrafficSpotDst',width:'140'}
],
},
{id:440,label:'二级表头',prop:'',width:'',children:[
{id:441,label:'三级表头(km)',prop:'trackTrafficNetNum',width:'110'},
{id:442,label:'三级表头(km/km²)',prop:'trackTrafficNetDst',width:'140'}
],
},
{id:450,label:'二级表头',prop:'',width:'',children:[
{id:451,label:'三级表头(个)',prop:'cityTrafficHubNum',width:'110'},
{id:452,label:'三级表头(个/km²)',prop:'cityTrafficHubDst',width:'110'},
{id:453,label:'三级表头(人次/km²)',prop:'cityTrafficHubFlow',width:'140'}
],
},
{id:460,label:'二级表头',prop:'',width:'',children:[
{id:461,label:'三级表头(km)',prop:'cityTrafficNetNum',width:'110'},
{id:462,label:'三级表头',prop:'cityTrafficNetDst',width:'140'}
],
},
]},
{id:500,label:'一级表头',prop:'',width:'',children:[
{id:510,label:'二级表头',prop:'',width:'',children:[
{id:511,label:'三级表头(km²)',prop:'pubServeLandArea',width:'110'},
{id:512,label:'三级表头',prop:'pubServeLandDst',width:'110'}
],
},
{id:520,label:'二级表头',prop:'',width:'',children:[
{id:521,label:'三级表头(个)',prop:'hospitalResourcesNum',width:'110'},
{id:522,label:'三级表头(km²)',prop:'hospitalResourcesArea',width:'110'},
{id:523,label:'三级表头(个/km²)',prop:'hospitalResourcesDst',width:'110'}
],
},{id:530,label:'二级表头',prop:'',width:'',children:[
{id:531,label:'三级表头(个)',prop:'schoolResourcesNum',width:'110'},
{id:532,label:'三级表头(km²)',prop:'schoolResourcesArea',width:'110'},
{id:533,label:'三级表头(个/km²)',prop:'schoolResourcesDst',width:'110'}
],
},
{id:540,label:'二级表头',prop:'',width:'',children:[
{id:541,label:'三级表头(个)',prop:'humanResourcesNum',width:'110'},
{id:542,label:'三级表头(个/km²)',prop:'humanResourcesDst',width:'110'}
],
},
{id:550,label:'二级表头',prop:'',width:'',children:[
{id:551,label:'三级表头(个)',prop:'businessResourcesNum',width:'110'},
{id:552,label:'三级表头(个/km²)',prop:'businessResourcesDst',width:'110'}
],
},
{id:560,label:'二级表头',prop:'',width:'',children:[
{id:561,label:'三级表头(个)',prop:'environResourcesNum',width:'110'},
{id:562,label:'三级表头(个/km²)',prop:'environResourcesDst',width:'110'}
],
},
]},
{id:600,label:'一级表头',prop:'',width:'',children:[
{id:610,label:'二级表头',prop:'',width:'',children:[
{id:611,label:'三级表头(分)',prop:'populationScore',width:'110'},
],
},
{id:620,label:'二级表头',prop:'',width:'',children:[
{id:621,label:'三级表头(分)',prop:'landScore',width:'110'},
],
},{id:630,label:'二级表头',prop:'',width:'',children:[
{id:631,label:'三级表头(分)',prop:'trafficScore',width:'110'},
],
},
{id:640,label:'二级表头',prop:'',width:'',children:[
{id:641,label:'三级表头(分)',prop:'communalFacilitiesScore',width:'110'},
],
},
{id:650,label:'二级表头',prop:'',width:'',children:[
{id:651,label:'三级表头(分)',prop:'modelScore',width:'110'},
],
}
]},
],

注:动态生成表头必须配置"key"

view:

vue+element-ui动态生成多级表头的方法

以上这篇vue+element-ui动态生成多级表头的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Javascript 相关文章推荐
xml分页+ajax请求数据源+dom取结果实例代码
Oct 31 Javascript
javascript拓展DOM操作 prependChild insertAfert
Nov 17 Javascript
推荐10个超棒的jQuery工具提示插件
Oct 11 Javascript
解析页面加载与js函数的执行 onload or ready
Dec 12 Javascript
jQuery 常用代码集锦(必看篇)
May 16 Javascript
javascript弹出窗口中增加确定取消按钮
Jun 24 Javascript
javascript简写常用的12个技巧(可以大大减少你的js代码量)
Mar 28 Javascript
React 实现拖拽功能的示例代码
Jan 06 Javascript
JavaScript ES6常用基础知识总结
Feb 09 Javascript
vue + any-touch实现一个iscroll 实现拖拽和滑动动画效果
Apr 08 Javascript
纯javascript实现选择框的全选与反选功能
Apr 08 Javascript
微信小程序实现pdf、word等格式文件上传的方法
Sep 10 Javascript
jQuery实现的响应鼠标移动方向插件用法示例【附源码下载】
Aug 28 #jQuery
对Vue table 动态表格td可编辑的方法详解
Aug 28 #Javascript
微信小程序自定义组件封装及父子间组件传值的方法
Aug 28 #Javascript
layui实现文件或图片上传记录
Aug 28 #Javascript
利用vue.js把静态json绑定bootstrap的table方法
Aug 28 #Javascript
react native 获取地理位置的方法示例
Aug 28 #Javascript
微信小程序自定义音乐进度条的实例代码
Aug 28 #Javascript
You might like
set_include_path在win和linux下的区别
2008/01/10 PHP
整理的9个实用的PHP库简介和下载
2010/11/09 PHP
Apache2中实现多网站域名绑定的实现方法
2011/06/01 PHP
深入解析php之apc
2013/05/15 PHP
thinkphp 多表 事务详解
2013/06/17 PHP
PHP多维数组遍历方法(2种实现方法)
2015/12/10 PHP
10个实用的脚本代码工具
2010/05/04 Javascript
JQuery最佳实践之精妙的自定义事件
2010/08/11 Javascript
JS复制到剪贴板示例代码
2013/10/30 Javascript
js设置控件的隐藏与显示的两种方法
2014/08/21 Javascript
百度地图自定义控件分享
2015/03/04 Javascript
Js实现自定义右键行为
2015/03/26 Javascript
jQuery图片特效插件Revealing实现拉伸放大
2015/04/22 Javascript
Javascript实现飞动广告效果的方法
2015/05/25 Javascript
jQuery针对input的class属性写了多个值情况下的选择方法
2016/06/03 Javascript
微信小程序  modal详解及实例代码
2016/11/09 Javascript
vue实现简单表格组件实例详解
2017/04/16 Javascript
bootstrap multiselect 多选功能实现方法
2017/06/05 Javascript
Vue父子模版传值及组件传值的三种方法
2017/11/27 Javascript
Vue中使用canvas方法总结
2019/02/12 Javascript
vue之a-table中实现清空选中的数据
2019/11/07 Javascript
WEB前端性能优化的7大手段详解
2020/02/04 Javascript
javascript设计模式 ? 中介者模式原理与用法实例分析
2020/04/20 Javascript
Node.js path模块,获取文件后缀名操作
2020/11/07 Javascript
[42:34]VP vs VG 2018国际邀请赛小组赛BO2 第一场 8.19
2018/08/21 DOTA
分享15个最受欢迎的Python开源框架
2014/07/13 Python
python学习之编写查询ip程序
2016/02/27 Python
简单的python协同过滤程序实例代码
2018/01/31 Python
Django压缩静态文件的实现方法详析
2018/08/26 Python
python实现12306登录并保存cookie的方法示例
2019/12/17 Python
python怎么判断素数
2020/07/01 Python
MAC平台基于Python Appium环境搭建过程图解
2020/08/13 Python
既然说Ruby中一切都是对象,那么Ruby中类也是对象吗
2013/01/26 面试题
领导班子在批评与自我批评座谈会上的发言
2014/09/28 职场文书
公文写作:工伤事故分析报告怎么写?
2019/11/05 职场文书
使用 Docker Compose 构建复杂的多容器App
2022/04/30 Servers