Blame view

src/components/radio/radio-group.vue 2.06 KB
7fa943eb   梁灏   init
1
2
3
4
5
6
7
  <template>
      <div :class="classes">
          <slot></slot>
      </div>
  </template>
  <script>
      import { oneOf } 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
37
          data () {
              return {
                  currentValue: this.value
cbe03a12   梁灏   support Checkbox
38
              };
06322514   梁灏   support Radio
39
          },
7fa943eb   梁灏   init
40
41
42
43
44
45
          computed: {
              classes () {
                  return [
                      `${prefixCls}`,
                      {
                          [`${prefixCls}-${this.size}`]: !!this.size,
5722a6fb   梁灏   RadioGroup add ve...
46
47
                          [`${prefixCls}-${this.type}`]: !!this.type,
                          [`${prefixCls}-vertical`]: this.vertical
7fa943eb   梁灏   init
48
                      }
b0893113   jingsam   :art: add eslint
49
                  ];
7fa943eb   梁灏   init
50
51
              }
          },
06322514   梁灏   support Radio
52
53
          mounted () {
              this.updateValue();
7fa943eb   梁灏   init
54
55
          },
          methods: {
06322514   梁灏   support Radio
56
57
              updateValue () {
                  const value = this.value;
7fa943eb   梁灏   init
58
                  this.$children.forEach((child) => {
06322514   梁灏   support Radio
59
                      child.currentValue = value == child.label;
7fa943eb   梁灏   init
60
61
62
63
                      child.group = true;
                  });
              },
              change (data) {
06322514   梁灏   support Radio
64
65
66
                  this.currentValue = data.value;
                  this.updateValue();
                  this.$emit('input', data.value);
7fa943eb   梁灏   init
67
                  this.$emit('on-change', data.value);
cd78c9c4   梁灏   some comps suppor...
68
                  this.dispatch('FormItem', 'on-form-change', data.value);
7fa943eb   梁灏   init
69
70
71
              }
          },
          watch: {
06322514   梁灏   support Radio
72
73
              value () {
                  this.updateValue();
7fa943eb   梁灏   init
74
75
              }
          }
b0893113   jingsam   :art: add eslint
76
77
      };
  </script>