Explorar o código

fix checkbox dynamic init bug (#1511)

baiyaaaaa %!s(int64=8) %!d(string=hai) anos
pai
achega
8ba89af678
Modificáronse 2 ficheiros con 17 adicións e 11 borrados
  1. 0 5
      packages/checkbox/src/checkbox-group.vue
  2. 17 6
      packages/checkbox/src/checkbox.vue

+ 0 - 5
packages/checkbox/src/checkbox-group.vue

@@ -16,12 +16,7 @@
       value(value) {
         this.$emit('change', value);
         this.dispatch('ElFormItem', 'el.form.change', [value]);
-        this.broadcast('ElCheckbox', 'initData', [value]);
       }
-    },
-
-    mounted() {
-      this.broadcast('ElCheckbox', 'initData', [this.value]);
     }
   };
 </script>

+ 17 - 6
packages/checkbox/src/checkbox.vue

@@ -72,6 +72,23 @@
         } else if (this.model !== null && this.model !== undefined) {
           return this.model === this.trueLabel;
         }
+      },
+
+      isGroup() {
+        let parent = this.$parent;
+        while (parent) {
+          if (parent.$options.componentName !== 'ElCheckboxGroup') {
+            parent = parent.$parent;
+          } else {
+            this._checkboxGroup = parent;
+            return true;
+          }
+        }
+        return false;
+      },
+
+      store() {
+        return this._checkboxGroup.value;
       }
     },
 
@@ -88,7 +105,6 @@
 
     data() {
       return {
-        store: [],
         isGroup: false
       };
     },
@@ -105,11 +121,6 @@
 
     created() {
       this.checked && this.addToStore();
-      this.$on('initData', data => {
-        this.store = data;
-        this.isGroup = true;
-        this.checked && this.addToStore();
-      });
     }
   };
 </script>