先看效果图:
利用组件自带属性header-row-style来完成。注意一定不要全局设置表头颜色,因为全局设置必须加!important,这样我们就无法覆盖了。
若项目有其他表格要设置背景色,可以通过在el-table中添加这句话就可以了,一行代码也不费劲,:header-cell-style="{background:'#fffaee'}"
<el-table ref="dateTable" :data="tableData" :header-cell-style="tableHeaderColor" border stripe>
// 修改表头颜色
tableHeaderColor ({ rowIndex, columnIndex }) {
if (rowIndex === 0 && columnIndex === 0) {
return { background: '#fffaee' }
} else if (rowIndex === 0 && columnIndex !== 0) {
return { background: '#FFBD7C', border: '0' }
} else {
return { background: '#fffaee' }
}
},
好啦,就酱紫吧,拜拜~~~~