详解element-ui el-table表格中勾选checkbox(selection),高亮当前行高亮某一行(某一行设置特殊的样式)

<template>
    <el-table 
    class="table" 
    ref="table" 
    :data="tableData" 
    :row-class-name="row_class_name"
    @selection-change="selection_change" 
    @row-click="row_click">
        <el-table-column type="selection" width="50" />
        <el-table-column prop="value" label="序号" width="50" />
        <el-table-column prop="label" label="列名" minWidth="100" />
    </el-table>
</template>
    
<script>
export default {
    data() {
        return {
            selection: [],
            tableData: [
                { label: '显示文本1', value: 1 },
                { label: '显示文本2', value: 2 },
                { label: '显示文本3', value: 3 },
                { label: '显示文本4', value: 4 },
                { label: '显示文本5', value: 5 },
            ],
        }
    },
    methods: {
        row_class_name({ row, rowIndex }) {
            return this.selection.find(v => v.value == row.value) ? 'selected' : '';
        },
        selection_change(selection) {
            this.selection = selection;
        },
        row_click(row, column, event) {
            this.$refs.table.toggleRowSelection(row)
        },
    }
};
</script>
    
<style lang="scss" scoped> 
.table {
     >>>tr.selected {
         $backgroundColor: #E6A23C; // 高亮选中行背景色 
         background-color: $backgroundColor ;
         td {
             background-color: $backgroundColor !important;
         }
     }
 }
</style>

  • 5
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值