button.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <button :class="clsStyle" :disabled="disabled" @click="clickHandler">
  3. <nut-icon class="txt-icon" v-if="icon != ''" :type="icon" :color="this.color"></nut-icon>
  4. <span :style="{ color: this.color }">
  5. <slot></slot>
  6. </span>
  7. </button>
  8. </template>
  9. <script>
  10. import Icon from './../icon/icon.vue';
  11. export default {
  12. name: 'nut-button',
  13. props: {
  14. type: {
  15. type: String,
  16. default: ''
  17. },
  18. shape: {
  19. type: String,
  20. default: ''
  21. },
  22. icon: {
  23. type: String,
  24. default: ''
  25. },
  26. disabled: {
  27. type: Boolean,
  28. default: false
  29. },
  30. block: {
  31. type: Boolean,
  32. default: false
  33. },
  34. small: {
  35. type: Boolean,
  36. default: false
  37. },
  38. label: {
  39. type: Boolean,
  40. default: false
  41. },
  42. color: {
  43. type: String,
  44. default: ''
  45. }
  46. },
  47. components: {
  48. 'nut-icon': Icon
  49. },
  50. computed: {
  51. clsStyle() {
  52. let cls = `nut-button ${this.type} ${this.shape}
  53. ${this.small ? ' small' : ''}
  54. ${this.block ? ' block' : ''}
  55. ${this.label ? ' label' : ''}
  56. ${!this.$slots.default ? (this.small ? 'no-txt-small' : 'no-txt') : ''}`;
  57. return cls;
  58. }
  59. },
  60. methods: {
  61. clickHandler(event) {
  62. // 如果是loading就阻止点击
  63. if (this.disabled) {
  64. return;
  65. }
  66. this.$emit('click', event);
  67. }
  68. }
  69. };
  70. </script>