element-ui 中 table 组件设置单元格高度时,当单元格高度很大时,是很好设置的,但是当单元格高度只有20px时,却有很多坑。 解决方案,首先设置:
<el-table size="mini"></el-table>
但是设置mini后单元格最小高度也有36px高,如果需要设置20px左右高的表格怎么办, 这时候需要在
<el-table :cell-style="cellStyle" size="mini"></el-table>
加上cell-style属性,然后在methods中设置padding:0; 就可以了
// 单元格样式
cellStyle(){
return 'font-size:12px;height:20px;padding:0;'
},
以上是表内容区域单元格的设置,另外表头单元格的高度设置,使用需要属性类名来设置
<el-table :header-cell-class-name="'header-cell'"></el-table>
.header-cell{
background-color: rgba(245, 247, 250, 1) !important;
font-weight: bold;
font-size:12px;
height:20px;
padding:0 !important;
color: @color-grey;
}