el-switch 自定义样式

效果:在这里插入图片描述
在这里插入图片描述

 <el-table-column fixed="right" label="审核" align="center" v-if="isShowdetails">
          <template slot-scope="scope">
            <el-switch class="switchStyle" 
            v-model="scope.row.approveResult"  
            active-text="通过"
            active-color="#13ce66" 
            inactive-color="#ff4949" 
            inactive-text="驳回" 
            :active-value="1"
            :inactive-value="0"
            @change="adoptBtn(scope.$index,examineTable,scope.row.approveResult)"></el-switch>
          </template>
        </el-table-column>
因为组件样式加上了scope 防止污染其他组件样式 所以需要使用/deep/来进行样式的修改
.switchStyle{
     /deep/ .el-switch__label {
            position: absolute;
            display: none;
            font-weight:normal;
        }
      /deep/ .el-switch__label *{
            font-size:12px;
        }
       /deep/ .el-switch__label--left {
            z-index: 9;
            left:22px;
            color: #fff;
        }
       /deep/ .el-switch__label--right {
            z-index: 9;
            color: #fff;
        }
       /deep/ .el-switch__label.is-active {
            display: block;
            height:30px;
            line-height:30px;
        }
    }
   /deep/ .switchStyle.el-switch .el-switch__core,.el-switch .el-switch__label {
        width:60px !important;
    }
    .el-switch,.el-switch__core{
        height:30px;
        line-height:30px;
    }
    .el-switch__core{
        border-radius:15px;
        &:after{
            width:20px;
            height:20px;
            top:4px;
            left:3px;
            z-index:10;
        }
    }
    .el-switch.is-checked .el-switch__core::after{
        margin-left:-23px;
    }
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
el-table是Element UI中的一个表格组件,可以通过自定义样式来改变表格的外观和交互效果。以下是一些自定义样式的方法: 1. 使用scoped CSS:在组件中使用scoped CSS,可以避免样式污染和冲突。例如: ``` <template> <el-table :data="tableData" style="width: 100%"> <el-table-column prop="name" label="Name"></el-table-column> <el-table-column prop="age" label="Age"></el-table-column> </el-table> </template> <style scoped> .el-table th, .el-table td { text-align: center; } </style> ``` 2. 使用CSS类名:可以通过添加CSS类名来自定义表格的样式。例如: ``` <template> <el-table :data="tableData" class="my-table" style="width: 100%"> <el-table-column prop="name" label="Name"></el-table-column> <el-table-column prop="age" label="Age"></el-table-column> </el-table> </template> <style> .my-table th, .my-table td { text-align: center; } </style> ``` 3. 使用slot-scope:可以通过slot-scope来自定义表格的单元格内容和样式。例如: ``` <template> <el-table :data="tableData" style="width: 100%"> <el-table-column prop="name" label="Name"> <template slot-scope="{ row }"> <span :class="{ 'highlight': row.age > 30 }">{{ row.name }}</span> </template> </el-table-column> <el-table-column prop="age" label="Age"></el-table-column> </el-table> </template> <style> .highlight { color: red; } </style> ``` 以上是el-table自定义样式的一些方法,可以根据实际需求选择合适的方法来实现自定义样式

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值