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 相关文章推荐
File, FileReader 和 Ajax 文件上传实例分析(php)
Apr 27 Javascript
JavaScript中变量提升 Hoisting
Jul 03 Javascript
replace()方法查找字符使用示例
Oct 28 Javascript
JavaScript控制各种浏览器全屏模式的方法、属性和事件介绍
Apr 03 Javascript
JavaScript Function函数类型介绍
Apr 08 Javascript
javascript实现的淘宝旅行通用日历组件用法实例
Aug 03 Javascript
基于JavaScript实现鼠标箭头移动图片跟着移动
Aug 30 Javascript
Vue.js 2.0 移动端拍照压缩图片预览及上传实例
Apr 27 Javascript
JavaScript登录验证基础教程
Nov 01 Javascript
webpack项目调试以及独立打包配置文件的方法
Feb 28 Javascript
vue中子组件传递数据给父组件的讲解
Jan 27 Javascript
React实现评论的添加和删除
Oct 20 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
PHP操作文件方法问答
2007/03/16 PHP
php在字符串中查找另一个字符串
2008/11/19 PHP
浅谈PHP强制类型转换,慎用!
2013/06/06 PHP
如何在PHP环境中使用ProtoBuf数据格式
2020/06/19 PHP
使用insertAfter()方法在现有元素后添加一个新元素
2014/05/28 Javascript
JavaScript图片轮播代码分享
2015/07/31 Javascript
javascript日期格式化方法汇总
2015/10/04 Javascript
深入学习JavaScript对象
2015/10/13 Javascript
使用微信内嵌H5网页解决JS倒计时失效问题
2017/01/13 Javascript
基于Node.js的WebSocket通信实现
2017/03/11 Javascript
聊聊JavaScript如何实现继承及特点
2017/04/07 Javascript
浅谈Angular 中何时取消订阅
2017/11/22 Javascript
JS组件系列之Gojs组件 前端图形化插件之利器
2017/11/29 Javascript
mpvue中使用flyjs全局拦截的实现代码
2018/09/13 Javascript
layui中的switch开关实现方法
2019/09/03 Javascript
对layer弹出框中icon数字参数的说明介绍
2019/09/04 Javascript
原生js实现文件上传、下载、封装等实例方法
2020/01/05 Javascript
JavaScript鼠标拖拽事件详解
2020/04/03 Javascript
[06:33]DOTA2亚洲邀请赛小组赛第二日 TOP10精彩集锦
2015/01/31 DOTA
[44:40]KG vs LGD 2019国际邀请赛小组赛 BO2 第一场 8.15
2019/08/16 DOTA
python中执行shell命令的几个方法小结
2014/09/18 Python
Python中的MongoDB基本操作:连接、查询实例
2015/02/13 Python
python处理csv数据的方法
2015/03/11 Python
简单掌握Python的Collections模块中counter结构的用法
2016/07/07 Python
python中如何使用朴素贝叶斯算法
2017/04/06 Python
python获取当前目录路径和上级路径的实例
2018/04/26 Python
python3.6.3+opencv3.3.0实现动态人脸捕获
2018/05/25 Python
pandas 将索引值相加的方法
2018/11/15 Python
Python线性拟合实现函数与用法示例
2018/12/13 Python
django2.0扩展用户字段示例
2019/02/13 Python
python实现微信自动回复机器人功能
2019/07/11 Python
应用OpenCV和Python进行SIFT算法的实现详解
2019/08/21 Python
移动端html5模拟长按事件的实现方法
2018/09/30 HTML / CSS
美国在线艺术商店:HandmadePiece
2020/11/06 全球购物
全陪导游欢迎词
2014/01/17 职场文书
小学红领巾广播稿(3篇)
2014/09/13 职场文书