当前位置:   article > 正文

el-button封装_el-button 封装icon

el-button 封装icon

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>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138

2. 调用

<Buttons :size="elTableBtnSize" type="primary" @parentClick="showEditPopup(scope.row)">
	<span slot="title">编辑</span>
</Buttons>
  • 1
  • 2
  • 3
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/喵喵爱编程/article/detail/748104
推荐阅读
相关标签
  

闽ICP备14008679号