Blame view

src/components/button/button.vue 3.81 KB
7fa943eb   梁灏   init
1
  <template>
bc6eb6f3   梁灏   Button add to, re...
2
3
4
5
6
7
8
9
10
11
12
      <a
          v-if="to"
          :class="classes"
          :disabled="disabled"
          :href="linkUrl"
          :target="target"
          @click="handleClickLink">
          <Icon class="ivu-load-loop" type="load-c" v-if="loading"></Icon>
          <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">
9817ce99   jingsam   :hammer: Use Icon...
19
          <Icon class="ivu-load-loop" type="load-c" 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
71
72
73
74
75
76
77
78
79
80
81
82
83
              },
              to: {
                  type: [Object, String]
              },
              replace: {
                  type: Boolean,
                  default: false
              },
              target: {
                  type: String,
                  validator (value) {
                      return oneOf(value, ['_blank', '_self', '_parent', '_top']);
                  },
                  default: '_self'
71d9fc8e   梁灏   Button add new pr...
84
              }
7fa943eb   梁灏   init
85
          },
698e3b61   梁灏   iButton add some ...
86
87
          data () {
              return {
698e3b61   梁灏   iButton add some ...
88
                  showSlot: true
b0893113   jingsam   :art: add eslint
89
              };
698e3b61   梁灏   iButton add some ...
90
          },
7fa943eb   梁灏   init
91
92
93
94
95
96
          computed: {
              classes () {
                  return [
                      `${prefixCls}`,
                      {
                          [`${prefixCls}-${this.type}`]: !!this.type,
71d9fc8e   梁灏   Button add new pr...
97
                          [`${prefixCls}-long`]: this.long,
7fa943eb   梁灏   init
98
99
                          [`${prefixCls}-${this.shape}`]: !!this.shape,
                          [`${prefixCls}-${this.size}`]: !!this.size,
698e3b61   梁灏   iButton add some ...
100
                          [`${prefixCls}-loading`]: this.loading != null && this.loading,
3d1f3cf6   梁灏   close #3402
101
                          [`${prefixCls}-icon-only`]: !this.showSlot && (!!this.icon || !!this.customIcon || this.loading)
7fa943eb   梁灏   init
102
                      }
b0893113   jingsam   :art: add eslint
103
                  ];
7fa943eb   梁灏   init
104
              }
698e3b61   梁灏   iButton add some ...
105
          },
99d0429e   梁灏   update Button & T...
106
          methods: {
bc6eb6f3   梁灏   Button add to, re...
107
              handleClickLink (event) {
99d0429e   梁灏   update Button & T...
108
                  this.$emit('click', event);
bc6eb6f3   梁灏   Button add to, re...
109
110
111
112
113
114
115
116
117
  
                  if (this.to) {
                      if (this.target === '_blank') {
                          return false;
                      } else {
                          event.preventDefault();
                          this.handleClick();
                      }
                  }
9e5c7283   梁灏   Revert "Revert "u...
118
              }
99d0429e   梁灏   update Button & T...
119
          },
d47ea998   梁灏   support Button an...
120
          mounted () {
99d0429e   梁灏   update Button & T...
121
              this.showSlot = this.$slots.default !== undefined;
7fa943eb   梁灏   init
122
          }
b0893113   jingsam   :art: add eslint
123
      };
d6342fe1   jingsam   fixed ie bug
124
  </script>