vue项目中 一行文本 文字 根据关键字 改变颜色 改变展示颜色

vue项目中 一行文本 文字 根据关键字 改变颜色 改变展示颜色

在这里插入图片描述

  • 搜索农业 农业颜色变为蓝色
  • 代码 v-html=“item.title”
<el-form-item label="">
     <el-radio-group  v-model="form.secondRadioID">
              <el-row  v-for="item in disposeRadioList" :key="item.value">
                <el-radio :label="item.code"><span v-html="item.title"></span></el-radio>
              </el-row>
            </el-radio-group>
          </el-form-item>
1234567
  • 计算属性中对原有的数据进行更改为html的
computed:{
    disposeRadioList() {
      let tworadioList = JSON.parse(JSON.stringify(this.radioList))
      tworadioList.forEach(e=>{
        e.title = e.title.replace(/-/g, ' / ') // 吧- 替换为 /
        e.title = e.title.replace(this.value, `<font color='#409eff'>${this.value}</font>`)
        return e   // 吧对应的关键字 替换为 `<font color='#409eff'>${this.value}</font>`
              }) 
      return tworadioList
    },
  },
1234567891011
  • v-for=“item in disposeRadioList” v-html 使用即可
要修改 `el-radio` 组件的样式,可以使用以下方法: 1. 使用 CSS 全局样式修改 可以在全局样式文件添加以下 CSS 代码,来修改 `el-radio` 组件的样式: ```css /* 选状态下的圆点颜色 */ .el-radio__input.is-checked .el-radio__inner { background-color: #ff0000; /* 修改为红色 */ } /* 未选状态下的圆点颜色 */ .el-radio__input:not(.is-checked) .el-radio__inner::after { background-color: #00ff00; /* 修改为绿色 */ } /* 文字颜色 */ .el-radio__label { color: #0000ff; /* 修改为蓝色 */ } ``` 2. 使用 `>>>` / `/deep/` / `::v-deep` 选择器修改 可以在组件所在的页面或组件内部的 `<style>` 标签,使用 `>>>` / `/deep/` / `::v-deep` 选择器来修改 `el-radio` 组件的样式。例如: ```html <template> <div> <el-radio v-model="radio" label="1">选项一</el-radio> <el-radio v-model="radio" label="2">选项二</el-radio> </div> </template> <style scoped> /* 使用 >>> 选择器修改 */ /* 选状态下的圆点颜色 */ .el-radio__input.is-checked >>> .el-radio__inner { background-color: #ff0000; /* 修改为红色 */ } /* 未选状态下的圆点颜色 */ .el-radio__input:not(.is-checked) >>> .el-radio__inner::after { background-color: #00ff00; /* 修改为绿色 */ } /* 文字颜色 */ .el-radio__label { color: #0000ff; /* 修改为蓝色 */ } /* 使用 /deep/ 选择器修改 */ /* 选状态下的圆点颜色 */ .el-radio__input.is-checked /deep/ .el-radio__inner { background-color: #ff0000; /* 修改为红色 */ } /* 未选状态下的圆点颜色 */ .el-radio__input:not(.is-checked) /deep/ .el-radio__inner::after { background-color: #00ff00; /* 修改为绿色 */ } /* 文字颜色 */ .el-radio__label { color: #0000ff; /* 修改为蓝色 */ } /* 使用 ::v-deep 选择器修改 */ /* 选状态下的圆点颜色 */ .el-radio__input.is-checked ::v-deep .el-radio__inner { background-color: #ff0000; /* 修改为红色 */ } /* 未选状态下的圆点颜色 */ .el-radio__input:not(.is-checked) ::v-deep .el-radio__inner::after { background-color: #00ff00; /* 修改为绿色 */ } /* 文字颜色 */ .el-radio__label { color: #0000ff; /* 修改为蓝色 */ } </style> ``` 以上就是两种修改 `el-radio` 组件样式的方法。其,使用 CSS 全局样式修改的方法会影响到整个项目所有使用到 `el-radio` 组件的样式,而使用 `>>>` / `/deep/` / `::v-deep` 选择器修改的方法只会影响到当前页面或组件的 `el-radio` 组件的样式。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值