欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2023-11-23 20:16:10
vue+element html配置:
{{tabledata}}

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动态生成多级表头的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。