修改el-table行高

文章讲述了在使用Vue的ElementUI创建表格时,如何设置第一列背景颜色,调整单元格高度,以及遇到的bug——当行高低于一定值时不再变化。问题源于表格单元格的padding影响了height。解决方案是通过`cell-style`属性将单元格padding设为0。
摘要由CSDN通过智能技术生成

效果

需求

1. 设置表格第一列背景颜色

2.设置单元格高度

代码

html

<el-table 
    :data="this.fullData.jiankong.info.error" 
    border 
    style="width: 762px;height: 216px;"
    :row-style="{ height: '35px' }" 
    :cell-style="columnStyle">

    <el-table-column label="-" align="center" prop="name" :show-overflow-tooltip="true">
        <template slot-scope="scope">
            <dict-tag :options="dict.type.fullchain_build_fire" :value="scope.row.yjlx" />
        </template>
     </el-table-column>
     <el-table-column label="1列" align="center" prop="hs" :show-overflow-tooltip="true" />
     <el-table-column label="2列" align="center" prop="cs" :show-overflow-tooltip="true" />
     <el-table-column label="3列" align="center" prop="ys" :show-overflow-tooltip="true" />
     <el-table-column label="4列" align="center" prop="ls" :show-overflow-tooltip="true" />
</el-table>

js

       

    // 设置表格第一列背景色
    columnStyle({ row, column, rowIndex, columnIndex }) {
      if (columnIndex == 0) {
        return 'background:	#f8f8f9;padding:0;'
      }else{
        return 'padding:0;'
      }
    }

关键代码

:row-style="{ height: '35px' }"  //设置行高

:cell-style="columnStyle"        //修改单元格样式

    columnStyle(){}   //设置单元格样式(和row-style结合)

bug

        可以设置行高但低于一定值时不再变化既行高存在最小值

原因:

        表格单元格自带的padding属性撑开了格子导致height失效

解决方式:

        利用cell-style属性设置表格单元格padding为0

  • 12
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值