el-button封装

10 篇文章 0 订阅
9 篇文章 0 订阅

el-button封装


main.js引入全局组件

1. 组件

<template>
  <!--按钮二次封装-->
  <!--<el-button :style="buttonStyle">-->
  <el-button :size="size" :type="type" :icon="icon" :circle="circle" :title="title" :disabled="disabled" @click="handClick">
    <slot name="title"></slot>
  </el-button>
</template>

<script>
export default {
  name: "index",
  props: {
    size: {
      type: String,
      default: ""
    },
    type: {
      type: String,
      default: ""
    },
    icon: {
      type: String,
      default: ""
    },
    circle: {
      type: Boolean,
      default: false
    }, 
    title: {
      type: String,
      default: ""
    },
    disabled: {
      type: Boolean,
      default: false
    }, 

  },
  data() {
    return {}
  },
  components: {},
  mounted() { },
  methods: {
    handClick() {
      this.$emit('parentClick')
    }
  },
  watch: {},
  created() { },
  computed: {
    btnOption() {
      let type, size, icon
      switch (this.title) {
        case "查询":
        case "录入":
        case "导入":
        case "添加":
          type = 'primary'
          icon = ''
          break;
        case "批量删除":
          type = 'danger'
          icon = ''
          break;
        case "批量退回":
          type = 'danger'
          icon = ''
          break;
        case "清空":
          type = 'info'
          icon = ''
          break;
        case "保存":
        case "修改":
        case "确定":
          type = 'primary'
          size = 'medium'
          icon = ''
          break;
        case "关闭":
        case "取消":
          type = ''
          size = 'medium'
          icon = ''
          break;
        case "新增":
          type = 'primary'
          size = 'mini'
          icon = 'el-icon-plus'
          break;
        case "编辑":
          type = 'primary'
          size = 'mini'
          icon = 'el-icon-edit'
          break;
        case "查看":
          type = 'primary'
          size = 'mini'
          icon = 'el-icon-view'
          break;
        case "删除":
          type = 'danger'
          size = 'mini'
          icon = 'el-icon-delete'
          break;
        default:
          type = 'success'
          icon = ''
      }
      return { type, size, icon }
    },
    btnStyle() {
      const fontSize =
        this.btnOption.size == "mini" ? "12px" : this.size == "big" ? "16px" : this.size == "nomal" ? "14px" : "14px"
      return { fontSize }
    },
    buttonStyle() {
      let background = ""
      switch (this.type) {
        case "error":
          background = "red";
          break;
        case "default":
          background = "pink";
          break;
        case "success":
          background = "green";
          break;
      }
      const fontSize =
        this.size == "mini" ? "12px" : this.size == "big" ? "16px" : this.size == "nomal" ? "14px" : "14px"
      const borderColor = this.borderColor
      return { background, fontSize, borderColor }
    }
  },
}
</script>

2. 调用

<Buttons :size="elTableBtnSize" type="primary" @parentClick="showEditPopup(scope.row)">
	<span slot="title">编辑</span>
</Buttons>
  • 27
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值