Element UI表格隔行变色

本文介绍了两种在Element UI框架中实现表格隔行变色的方法。第一种是通过设置表格的'stripe'属性,结合CSS样式实现;第二种是利用'row-class-name'属性,配合methods中的方法动态给行添加类名来达到变色效果。注意,当使用'scoped'时,CSS样式将无法覆盖Element UI的默认样式,需避免此坑。
摘要由CSDN通过智能技术生成

表格隔行变色有两种方式

 第一种,我们给表格设置“stripe”属性

<el-table
          :data="tableWarningData"
          style="width: 100%"
          :header-cell-style="{ color: '#1572e9' }"
          stripe
          :cell-style="changeCellStyle">

然后在style里面写下如下代码 

.el-table--striped .el-table__body tr.el-table__row--striped.el-table__row--striped
.el-table__row--striped td {
  background-color:#eaf3fb;
}

第二种,我们给表格设置row-class-name属性

<el-table
            :data="tableCreditData"
            style="width: 100%"
            :header-cell-style="{ color: '#1572e9' }"
            :row-class-name="tableRowClassName">

然后在methods里面写下如下代码

// 表格隔行变色
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 === 0) {
        return 'success-row' //这是类名
      } else  {
        return ''
      }
    },

在style里面写下“success-row”类的样式

.success-row {
  background-color:#eaf3fb !important; 

}

注意样式要写在<style lang="scss"></style>里面,我之前一直在写在<style lang="scss" scoped></style>里面,导致隔行没有效果,加了"scoped"就是限制样式只能在本组件中使用,就不能覆盖element-ui里面的样式,避坑!!!

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值