fix checkbox dynamic init bug (#1511)

pull/1514/head
baiyaaaaa 2016-12-02 08:08:12 +08:00 committed by cinwell.li
parent 34dbb01c1a
commit 8ba89af678
2 changed files with 17 additions and 11 deletions

View File

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

View File

@ -72,6 +72,23 @@
} else if (this.model !== null && this.model !== undefined) { } else if (this.model !== null && this.model !== undefined) {
return this.model === this.trueLabel; 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() { data() {
return { return {
store: [],
isGroup: false isGroup: false
}; };
}, },
@ -105,11 +121,6 @@
created() { created() {
this.checked && this.addToStore(); this.checked && this.addToStore();
this.$on('initData', data => {
this.store = data;
this.isGroup = true;
this.checked && this.addToStore();
});
} }
}; };
</script> </script>