二次封装动态的el-button组件

33 篇文章 0 订阅

效果如下
在这里插入图片描述
举个栗子,我想要编辑和删除按钮颜色是16进制的,代码如下

<template>
  <el-button
    class="type-button"
    type="text"
    :icon="iconfont"
    :class="[classes, type == '编辑' ? 'orange' : '', type == '删除' ? 'gray' : '']"
    v-bind="$attrs"
    v-on="$listeners"
  >
    <slot>{{ this.type }}</slot>
  </el-button>
</template>

<script>
export default {
  name: "type-button",
  props: {
    type: {
      type: [String, undefined],
      default: undefined
    },
    icon: {
      type: [String, undefined],
      default: undefined
    },
    color: {
      type: [String, undefined],
      default: undefined
    }
  },
  computed: {
    findTypes() {
      switch (this.type) {
        case "删除":
          return {
            color: "danger",
            icon: "el-icon-delete"
          }
        case "编辑":
          return {
            color: "info",
            icon: "gansu-icon-bianji"
          }
        case "查看":
          return {
            color: "priamry",
            icon: "el-icon-setting"
          }
        case "详情":
          return {
            color: "priamry",
            icon: "el-icon-more"
          }
        default:
          return {
            color: this.color,
            icon: this.icon
          }
      }
    },
    classes() {
      const color = this.color ? this.color : this.findTypes.color
      return `${color}--text`
    },
    iconfont() {
      return this.icon ? this.icon : this.findTypes.icon
    }
  }
}
</script>

<style lang="scss" scoped>
.orange {
  color: #ff5400 !important;
}
.orange.is-disabled {
  color: #d8d9db !important;
}
.gray {
  color: #666666 !important;
}
.gray.is-disabled {
  color: #d8d9db !important;
}
</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值