Blame view

src/components/checkbox/checkbox-group.vue 1.46 KB
7fa943eb   梁灏   init
1
2
3
4
5
6
  <template>
      <div :class="classes">
          <slot></slot>
      </div>
  </template>
  <script>
cd78c9c4   梁灏   some comps suppor...
7
      import Emitter from '../../mixins/emitter';
7fa943eb   梁灏   init
8
9
10
      const prefixCls = 'ivu-checkbox-group';
  
      export default {
34ee7b4a   梁灏   support Tree & ad...
11
          name: 'CheckboxGroup',
cd78c9c4   梁灏   some comps suppor...
12
          mixins: [ Emitter ],
7fa943eb   梁灏   init
13
          props: {
cbe03a12   梁灏   support Checkbox
14
              value: {
7fa943eb   梁灏   init
15
                  type: Array,
6ff31952   梁灏   optimize Input sh...
16
                  default () {
b0893113   jingsam   :art: add eslint
17
                      return [];
6ff31952   梁灏   optimize Input sh...
18
                  }
7fa943eb   梁灏   init
19
20
              }
          },
cbe03a12   梁灏   support Checkbox
21
22
23
24
25
          data () {
              return {
                  currentValue: this.value
              };
          },
7fa943eb   梁灏   init
26
27
28
29
30
          computed: {
              classes () {
                  return `${prefixCls}`;
              }
          },
cbe03a12   梁灏   support Checkbox
31
          mounted () {
7fa943eb   梁灏   init
32
33
34
35
              this.updateModel(true);
          },
          methods: {
              updateModel (update) {
cbe03a12   梁灏   support Checkbox
36
                  const value = this.value;
7fa943eb   梁灏   init
37
38
  
                  this.$children.forEach((child) => {
cbe03a12   梁灏   support Checkbox
39
                      child.model = value;
7fa943eb   梁灏   init
40
41
  
                      if (update) {
cbe03a12   梁灏   support Checkbox
42
                          child.currentValue = value.indexOf(child.label) >= 0;
7fa943eb   梁灏   init
43
44
45
46
47
                          child.group = true;
                      }
                  });
              },
              change (data) {
cbe03a12   梁灏   support Checkbox
48
49
                  this.currentValue = data;
                  this.$emit('input', data);
7fa943eb   梁灏   init
50
                  this.$emit('on-change', data);
cd78c9c4   梁灏   some comps suppor...
51
                  this.dispatch('FormItem', 'on-form-change', data);
7fa943eb   梁灏   init
52
53
54
              }
          },
          watch: {
cbe03a12   梁灏   support Checkbox
55
              value () {
c1f6da1f   梁灏   fixed CheckboxGro...
56
                  this.updateModel(true);
7fa943eb   梁灏   init
57
58
              }
          }
b0893113   jingsam   :art: add eslint
59
60
      };
  </script>