vue点击按钮互斥效果

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

vue点击按钮互斥效果

麦兜:)   2022-05-28 我要评论

先看看实现的效果吧!

步骤:

一.html代码

<!-- 等级筛选 -->
    <div class="level-screening">
      <el-button
        size="medium"
        type="primary"
        :class="index==itemType?'highlight':''"
        v-for="(item,index) in levelList"
        :key="index"
        @click.prevent="materTay(index,item.code)"
      >
        {{ item.codeValue }}</el-button
      >
</div>

二.css(less)代码

.level-screening {
      padding-left: 40px;
      box-sizing: border-box;
      height: 120px;
      text-align: left;
      line-height: 80px;
      .el-button {
        border-color: #0085f4;
        background-color: #fff;
        color: #0085f4;
      }
      .highlight {
        background-color: #8e66f6 !important;
        color: #fff;
      }
    }

三.js代码

export default {
 data() {
    return {
       levelList: [
        {
          code: '',
          codeValue: '全部'
        },
        {
          code: '',
          codeValue: '铜'
        },
        {
          code: '',
          codeValue: '银'
        },
        {
          code: '',
          codeValue: '金'
        },
        {
          code: '',
          codeValue: '白金'
        },
        {
          code: '',
          codeValue: '铂金'
        }
      ], // 等级筛选数据
      itemType: 0, // 等级筛选选中的标识
      materialCode: '' // 分类的code值
        }
    },
   methods: {
    // 等级筛选互斥效果
    materTay(itemType, code) {
      // 等级筛选选中的标识-高亮效果
      this.itemType = itemType
      // 分类的code值
      this.materialCode = code
    }
  }
}

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们