Blame view

src/components/button/button.vue 3.19 KB
7fa943eb   梁灏   init
1
  <template>
bc6eb6f3   梁灏   Button add to, re...
2
3
4
5
6
7
8
      <a
          v-if="to"
          :class="classes"
          :disabled="disabled"
          :href="linkUrl"
          :target="target"
          @click="handleClickLink">
929fdf5c   梁灏   update loading icon
9
          <Icon class="ivu-load-loop" type="ios-loading" v-if="loading"></Icon>
bc6eb6f3   梁灏   Button add to, re...
10
11
12
          <Icon :type="icon" :custom="customIcon" v-if="(icon || customIcon) && !loading"></Icon>
          <span v-if="showSlot" ref="slot"><slot></slot></span>
      </a>
8cc60d22   Graham Fairweather   Use an added styl...
13
      <button
bc6eb6f3   梁灏   Button add to, re...
14
          v-else
8cc60d22   Graham Fairweather   Use an added styl...
15
16
17
          :type="htmlType"
          :class="classes"
          :disabled="disabled"
bc6eb6f3   梁灏   Button add to, re...
18
          @click="handleClickLink">
929fdf5c   梁灏   update loading icon
19
          <Icon class="ivu-load-loop" type="ios-loading" v-if="loading"></Icon>
3d1f3cf6   梁灏   close #3402
20
          <Icon :type="icon" :custom="customIcon" v-if="(icon || customIcon) && !loading"></Icon>
d47ea998   梁灏   support Button an...
21
          <span v-if="showSlot" ref="slot"><slot></slot></span>
7fa943eb   梁灏   init
22
23
24
25
26
      </button>
  </template>
  <script>
      import Icon from '../icon';
      import { oneOf } from '../../utils/assist';
bc6eb6f3   梁灏   Button add to, re...
27
      import mixinsLink from '../../mixins/link';
7fa943eb   梁灏   init
28
29
  
      const prefixCls = 'ivu-btn';
7fa943eb   梁灏   init
30
31
  
      export default {
06322514   梁灏   support Radio
32
          name: 'Button',
bc6eb6f3   梁灏   Button add to, re...
33
          mixins: [ mixinsLink ],
7fa943eb   梁灏   init
34
35
36
37
          components: { Icon },
          props: {
              type: {
                  validator (value) {
6c912a7b   梁灏   update Button
38
                      return oneOf(value, ['primary', 'ghost', 'dashed', 'text', 'info', 'success', 'warning', 'error', 'default']);
7fa943eb   梁灏   init
39
40
41
42
43
44
45
46
47
                  }
              },
              shape: {
                  validator (value) {
                      return oneOf(value, ['circle', 'circle-outline']);
                  }
              },
              size: {
                  validator (value) {
77f1cc2e   梁灏   Checkbox add size...
48
                      return oneOf(value, ['small', 'large', 'default']);
7fa943eb   梁灏   init
49
50
51
52
53
54
55
56
57
58
                  }
              },
              loading: Boolean,
              disabled: Boolean,
              htmlType: {
                  default: 'button',
                  validator (value) {
                      return oneOf(value, ['button', 'submit', 'reset']);
                  }
              },
3d1f3cf6   梁灏   close #3402
59
60
61
62
63
64
65
66
              icon: {
                  type: String,
                  default: ''
              },
              customIcon: {
                  type: String,
                  default: ''
              },
71d9fc8e   梁灏   Button add new pr...
67
68
69
              long: {
                  type: Boolean,
                  default: false
bc6eb6f3   梁灏   Button add to, re...
70
              },
7fa943eb   梁灏   init
71
          },
698e3b61   梁灏   iButton add some ...
72
73
          data () {
              return {
698e3b61   梁灏   iButton add some ...
74
                  showSlot: true
b0893113   jingsam   :art: add eslint
75
              };
698e3b61   梁灏   iButton add some ...
76
          },
7fa943eb   梁灏   init
77
78
79
80
81
82
          computed: {
              classes () {
                  return [
                      `${prefixCls}`,
                      {
                          [`${prefixCls}-${this.type}`]: !!this.type,
71d9fc8e   梁灏   Button add new pr...
83
                          [`${prefixCls}-long`]: this.long,
7fa943eb   梁灏   init
84
85
                          [`${prefixCls}-${this.shape}`]: !!this.shape,
                          [`${prefixCls}-${this.size}`]: !!this.size,
698e3b61   梁灏   iButton add some ...
86
                          [`${prefixCls}-loading`]: this.loading != null && this.loading,
3d1f3cf6   梁灏   close #3402
87
                          [`${prefixCls}-icon-only`]: !this.showSlot && (!!this.icon || !!this.customIcon || this.loading)
7fa943eb   梁灏   init
88
                      }
b0893113   jingsam   :art: add eslint
89
                  ];
7fa943eb   梁灏   init
90
              }
698e3b61   梁灏   iButton add some ...
91
          },
99d0429e   梁灏   update Button & T...
92
          methods: {
bc6eb6f3   梁灏   Button add to, re...
93
              handleClickLink (event) {
99d0429e   梁灏   update Button & T...
94
                  this.$emit('click', event);
bc6eb6f3   梁灏   Button add to, re...
95
  
7d0b7384   梁灏   fixed #3484
96
                  this.handleCheckClick(event);
9e5c7283   梁灏   Revert "Revert "u...
97
              }
99d0429e   梁灏   update Button & T...
98
          },
d47ea998   梁灏   support Button an...
99
          mounted () {
99d0429e   梁灏   update Button & T...
100
              this.showSlot = this.$slots.default !== undefined;
7fa943eb   梁灏   init
101
          }
b0893113   jingsam   :art: add eslint
102
      };
d6342fe1   jingsam   fixed ie bug
103
  </script>