Blame view

src/components/radio/radio-group.vue 2 KB
7fa943eb   梁灏   init
1
2
3
4
5
6
7
8
9
10
11
  <template>
      <div :class="classes">
          <slot></slot>
      </div>
  </template>
  <script>
      import { oneOf } from '../../utils/assist';
  
      const prefixCls = 'ivu-radio-group';
  
      export default {
578ca325   梁灏   fixed Radio bug
12
          name: 'radioGroup',
7fa943eb   梁灏   init
13
          props: {
06322514   梁灏   support Radio
14
              value: {
7fa943eb   梁灏   init
15
16
17
18
19
20
21
22
23
24
25
26
                  type: [String, Number],
                  default: ''
              },
              size: {
                  validator (value) {
                      return oneOf(value, ['small', 'large']);
                  }
              },
              type: {
                  validator (value) {
                      return oneOf(value, ['button']);
                  }
5722a6fb   梁灏   RadioGroup add ve...
27
28
29
30
              },
              vertical: {
                  type: Boolean,
                  default: false
7fa943eb   梁灏   init
31
32
              }
          },
06322514   梁灏   support Radio
33
34
35
36
37
          data () {
              return {
                  currentValue: this.value
              }
          },
7fa943eb   梁灏   init
38
39
40
41
42
43
          computed: {
              classes () {
                  return [
                      `${prefixCls}`,
                      {
                          [`${prefixCls}-${this.size}`]: !!this.size,
5722a6fb   梁灏   RadioGroup add ve...
44
45
                          [`${prefixCls}-${this.type}`]: !!this.type,
                          [`${prefixCls}-vertical`]: this.vertical
7fa943eb   梁灏   init
46
                      }
b0893113   jingsam   :art: add eslint
47
                  ];
7fa943eb   梁灏   init
48
49
              }
          },
06322514   梁灏   support Radio
50
51
          mounted () {
              this.updateValue();
7fa943eb   梁灏   init
52
53
          },
          methods: {
06322514   梁灏   support Radio
54
55
              updateValue () {
                  const value = this.value;
7fa943eb   梁灏   init
56
                  this.$children.forEach((child) => {
06322514   梁灏   support Radio
57
                      child.currentValue = value == child.label;
7fa943eb   梁灏   init
58
59
60
61
                      child.group = true;
                  });
              },
              change (data) {
06322514   梁灏   support Radio
62
63
64
                  this.currentValue = data.value;
                  this.updateValue();
                  this.$emit('input', data.value);
7fa943eb   梁灏   init
65
                  this.$emit('on-change', data.value);
06322514   梁灏   support Radio
66
67
                  // todo 事件
  //                this.$dispatch('on-form-change', data.value);
7fa943eb   梁灏   init
68
69
70
              }
          },
          watch: {
06322514   梁灏   support Radio
71
72
              value () {
                  this.updateValue();
7fa943eb   梁灏   init
73
74
              }
          }
b0893113   jingsam   :art: add eslint
75
76
      };
  </script>