一、首先动态生成表格需要满足一定的数据格式,比如以下表头的id要对应上表体数据的key
tableData:{
headList:[
{label:"机身颜色",id: "color"},
{label:"等级",id: "dengji"},
{label:"购买渠道",id: "ditch"},
{label:"价格",id:"price},
],
dataList:[
{ditch:"大陆",color:"白色",dengji:"A级",price:100},
{ditch:"国行",color:"黑色",dengji:"A级",price:50}
]
},
二、本次的需求是既满足动态生成表格还得操作单元格的背景颜色用到 :cell-style="cellClassName"
<templete>
<el-table :data="tableData.dataList" :cell-style="cellClassName" border style="width: 100%;margin-top:10px" :header-cell-style="{background:'#f8f8f9',color:'#515a6e'}">
<el-table-column align