2021-10-28

本文介绍了如何在Vue项目中使用`el-table`组件动态改变行颜色。关键在于设置`row-class-name`属性,结合自定义方法`tableRowClassName`判断行数据,当`commonState`为真时应用特定样式。同时展示了`el-table`的相关配置,包括列定义、事件监听等,以及对应的CSS样式实现。
摘要由CSDN通过智能技术生成

el-table动态改变行颜色【vue】

``

1.<el-table>标签中加属性:row-class-name="tableRowClassName"

<el-table :key="tableKey" ref="table" v-loading="loading" :data="tableData.records" border fit
              :row-class-name="tableRowClassName"
              row-key="id" @filter-change="filterChange" @selection-change="onSelectChange" @sort-change="sortChange"
              @cell-click="cellClick">
      <el-table-column align="center" type="selection" width="40px" column-key="selectionId" :reserve-selection="true"/>
      <el-table-column label="id" align="center" prop="id" sortable="custom"/>
      <el-table-column label="常用语" align="center" prop="commonWords"/>
      <el-table-column label="创建日期" align="center" prop="createTime"/>
      <el-table-column label="更新日期" align="center" prop="updateTime"/>
      <el-table-column label="操作" column-key="operation" align="center" class-name="small-padding fixed-width"
                       fixed="right" width="150px">
        <template slot-scope="{row}">
          <i class="el-icon-edit table-operation" style="color: #2db7f5;" v-if="row.commonState==null" @click="editRow(row)"/>
          <i class="el-icon-delete table-operation" style="color: #f50;" v-if="row.commonState==null" @click="del(row)"/>
        </template>
      </el-table-column>
    </el-table>


2.  methods: {}中添加方法tableRowClassName

    tableRowClassName({row}) {
      if(row.commonState === true) {
        return 'common-row';
      }
    },
    
3. 添加css样式
	<style>
	.el-table .common-row {
	  background: pink!important;
	}
	</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值