ref动态修改el-button字体颜色

一、效果图

二、代码

<template>
  <div>
    <el-button
      @mouseenter.native="onmouseover(item.id, index)"
      @mouseleave.native="onmouseout(item.id, index)"
      @click.native="click(item.id, index)"
      :ref="item.id + index"
      :key="item.id"
      v-for="(item, index) in data"
      >{{ item.name }}</el-button
    >
  </div>
</template>
<script>
export default {
  data() {
    return {
      data: [
       {
          id: '1',
          name: 'asd',
          color: '#f56c6c',
          color1: '#0de52b',
          color2: '#fff',
          isShow: false
        },
        {
          id: '2',
          name: 'qwe',
          color: '#0de52b',
          color1: '#f56c6c',
          color2: '#fff',
          isShow: false
        },
        {
          id: '3',
          name: 'zxc',
          color: '#5C4033',
          color1: '#CDCDCD',
          color2: '#4F2F4F',
          isShow: false
        },
        {
          id: '4',
          name: 'rty',
          color: '#CC3299',
          color1: '#D8D8BF',
          color2: '#99CC32',
          isShow: false
        }
      ]
    }
  },
  mounted() {
    this.data.forEach((item, index) => {
      this.$refs[`${item.id}${index}`][0].$el.style.color = item.color
    })
  },
  methods: {
    onmouseover(data, index) {
      if (this.data[index].isShow) return
      this.$refs[`${data}${index}`][0].$el.style.color = this.data[index].color1
    },
    onmouseout(data, index) {
      if (this.data[index].isShow) return
      this.$refs[`${data}${index}`][0].$el.style.color = this.data[index].color
    },
    click(data, index) {
      this.$nextTick(() => {
        this.data.forEach((item, indexs) => {
          if (index == indexs) {
            item.isShow = true
            this.$refs[`${data}${index}`][0].$el.style.color =
              this.data[index].color2
          } else {
            this.$refs[`${item.id}${indexs}`][0].$el.style.color = item.color
            item.isShow = false
          }
        })
      })
    }
  }
}
</script>
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
修改el-button的值,可以使用v-bind指令将一个变量绑定到el-button的value属性上。然后,当这个变量的值发生改变时,el-button的值也会相应改变。具体做法是,在el-button上添加v-bind:value="变量名"。当变量的值改变时,el-button的值也会自动更新。 另外,如果要根据不同的值来修改el-button的样式,可以使用三元运算符,根据对应的值改变按钮的颜色。具体的操作是在el-table-column表格中根据不同的值使用三元运算符来设置el-button的样式。 此外,你还可以使用v-if和v-else-if指令来根据不同的值显示不同的el-button。在这种情况下,你可以使用<hy-button>标签,并在标签内部使用<span>标签来设置按钮的文本。根据不同的值使用v-if和v-else-if来显示不同的按钮内容。 <span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [element-ui中select组件绑定值改变,触发change事件方法](https://download.csdn.net/download/weixin_38752897/12953519)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [el-button根据其他字段的值 改变button 按钮的值,实现页面功能及在同一个button中给不同的值添加点击事件](https://blog.csdn.net/qq_38254897/article/details/92806855)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值