Blame view

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