index.vue 1.1 KB
<template>
  <div class="zui-button" :class="classRender" :style="style" @click="onClick">
    <slot></slot>
  </div>
</template>

<script>
export default {
  name: 'Button',
  props: {
    type: {
      type: String,
      default: 'default',
    },
    size: {
      type: String,
      default: 'md',
    },
    block: {
      type: Boolean,
      default: false,
    },
    round: Boolean,
    square: Boolean,
    disabled: Boolean,
  },
  computed: {
    style: function () {
      return { display: this.block ? '' : 'inline-block', borderRadius: this.borderRadius };
    },
    borderRadius: function () {
      if (this.round) {
        return '1.25rem';
      } else if (this.square) {
        return '0';
      } else {
        return '0.25rem';
      }
    },
    classRender: function () {
      return [this.size, this.disabled ? 'disabled' : '', this.block ? 'block' : '', this.type];
    },
  },
  methods: {
    onClick: function () {
      if (this.$listeners['click'] && !this.disabled) {
        this.$emit('click');
      }
    },
  },
};
</script>

<style lang="scss">
@import './index.scss';
</style>