button.vue 1.5 KB

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