求助:element-plus如何实现动态多级表头?
vue
<el-table :data="tableData">
<el-table-column label="店员数量评级金额">
<template #default="scope">
<el-table-column v-for="(item,index) in scope.row.fullTimeNCs" :key="item" :label="item.label">
{{ item.price }}
</el-table-column>
</template>
</el-table-column>
</el-table>
script
<script setup>
import { ref } from "vue";
这是完整的表格数据,其中fullTimeNCs的长度是动态的
`const tableData = ref([
{
area: "NKA_门店1",
fullTimeNCs: [{label:'1个店员评级金额',price:"100"}, {label:'2个店员评级金额',price:"400"},{label:'3个店员评级金额',price: "600"}],
},
{
area: "NKA_门店12",
fullTimeNCs: [{label:'1个店员评级金额',price:"100"}, {label:'2个店员评级金额',price:"400"},{label:'3个店员评级金额',price: "600"}],
},
{
area: "NKA_门店13",
fullTimeNCs: [{label:'1个店员评级金额',price:"100"}, {label:'2个店员评级金额',price:"400"},{label:'3个店员评级金额',price: "600"}],
},
]);`
</script>
期望结果
店员数量是动态的,但是在这里无法循环渲染el-table-column多级表头
回复
1个回答
test
2024-06-25
<el-table :data="tableInfo.tableData">
<el-table-column label="地区" prop="area"></el-table-column>
<el-table-column label="店员数量评级金额">
<el-table-column v-for="item in tableInfo.headerList" :key="item.key" :label="item.label" :prop="item.key"> </el-table-column>
</el-table-column>
</el-table>
数据需要自己转下 或者后端就返回那种格式
tableInfo(){
let tableData= [
{
area: "NKA_门店1",
fullTimeNCs: [
{ label: "1个店员评级金额", price: "100" },
{ label: "2个店员评级金额", price: "400" },
{ label: "3个店员评级金额", price: "600" }
]
},
{
area: "NKA_门店12",
fullTimeNCs: [
{ label: "1个店员评级金额", price: "100" },
{ label: "2个店员评级金额", price: "400" },
{ label: "3个店员评级金额", price: "600" }
]
},
{
area: "NKA_门店13",
fullTimeNCs: [
{ label: "1个店员评级金额", price: "100" },
{ label: "2个店员评级金额", price: "400" },
{ label: "3个店员评级金额", price: "600" }
]
}
]
let headerList=[]
tableData.forEach((item)=>{
item.fullTimeNCs.forEach((citem,cindex)=>{
let key=`customFiled${cindex+1}`
item[key]=citem.price;
let find=headerList.find(i=>i.label==citem.label)
if(!find){
headerList.push({
key,
label:citem.label
})
}
})
})
return {
headerList,
tableData
}
}
回复
适合作为回答的
- 经过验证的有效解决办法
- 自己的经验指引,对解决问题有帮助
- 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
- 询问内容细节或回复楼层
- 与题目无关的内容
- “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容