Blame view

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