动态修改el-select 选中的值字体颜色 和下拉框字体颜色

    <el-table-column label="优先级" width="120">
              <template slot-scope="scope">
                <div
                  :class="{ 'priorit1': scope.row.taskLevel === 1, 'priorit2': 
                   scope.row.taskLevel === 2, 'priorit3': scope.row.taskLevel === 3, 
                   'priorit4':scope.row.taskLevel === 4 }">
                  <el-select v-model="scope.row.taskLevel" 
                     @change="precedence(scope.$index, scope.row)"
                    :style="selectItemStyle">
                    <el-option v-for="item in preceden" :key="item.value" 
                      :label="item.label" :value="item.value"
                      :style="{ color: priorityColor(item.value) }" />
                  </el-select>
                </div>
              </template>
            </el-table-column>



  methods: {

    priorityColor(value) {
      switch (value) {
        case 1:
          return 'red'; // 紧急 - 红色
        case 2:
          return 'orange'; // 高 - 橙色
        case 3:
          return 'blue'; // 中 - 蓝色
        case 4:
          return 'green'; // 低 - 绿色
        default:
          return 'black'; // 默认为黑色
      }
    },
}



::v-deep .priorit1 .el-input__inner {
  color: red;
}

::v-deep .priorit2 .el-input__inner {
  color: orange;
}

::v-deep .priorit3 .el-input__inner {
  color: blue;
}

::v-deep .priorit4 .el-input__inner {
  color: green;
}

     <el-table-column label="优先级" width="120">

              <template slot-scope="scope">

                <div   :class="{ 'priorit1': scope.row.taskLevel === 1, 'priorit2': scope.row.taskLevel === 2,      'priorit3': scope.row.taskLevel === 3, 'priorit4': scope.row.taskLevel === 4 }">

                  <el-select v-model="scope.row.taskLevel" @change="precedence(scope.$index,                                scope.row)" :style="selectItemStyle">

                    <el-option v-for="item in preceden" :key="item.value" :label="item.label"                                               :value="item.value   :style="{ color: priorityColor(item.value) }" />

                  </el-select>

                </div>

       </template>

 </el-table-column>

1.修改下拉框的字体颜色

  <el-option v-for="item in preceden" :key="item.value" :label="item.label"                                               :value="item.value   :style="{ color: priorityColor(item.value) }" /> 

在el-option 里边添加:style="{ color: priorityColor(item.value) }"  

  methods: {

priorityColor(value) {

      switch (value) {

        case 1:

          return 'red'; // 紧急 - 红色

        case 2:

          return 'orange'; // 高 - 橙色

        case 3:

          return 'blue'; // 中 - 蓝色

        case 4:

          return 'green'; // 低 - 绿色

}

    },

2.el-select 选中的值字体颜色 

在.el-select  使用div 包裹   动态添加类名   根据scope.row.taskLevel  值添加不同的类名

  <div   :class="{ 'priorit1': scope.row.taskLevel === 1, 'priorit2': scope.row.taskLevel === 2,      'priorit3': scope.row.taskLevel === 3, 'priorit4': scope.row.taskLevel === 4 }">

<style scoped lang="scss">

::v-deep .priorit1 .el-input__inner {

  color: red;

}

::v-deep .priorit2 .el-input__inner {

  color: orange;

}

::v-deep .priorit3 .el-input__inner {

  color: blue;

}

::v-deep .priorit4 .el-input__inner {

  color: green;

}

</style >

虽然办法笨   但可行

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值