Form: remove emitter (#4532)

This commit is contained in:
cinwell.li
2017-05-02 10:25:39 +08:00
committed by baiyaaaaa
parent 72b1bc3c10
commit fff7dddd94
4 changed files with 38 additions and 36 deletions

View File

@@ -1,12 +1,16 @@
<script>
import Emitter from 'element-ui/src/mixins/emitter';
export default {
name: 'ElCheckboxGroup',
componentName: 'ElCheckboxGroup',
mixins: [Emitter],
provide() {
return {
ElCheckboxGroup: this
};
},
inject: ['ElFormItem'],
props: {
value: {},
@@ -19,7 +23,7 @@
watch: {
value(value) {
this.dispatch('ElFormItem', 'el.form.change', [value]);
this.ElFormItem.$emit('el.form.change', value);
}
}
};

View File

@@ -40,13 +40,9 @@
</label>
</template>
<script>
import Emitter from 'element-ui/src/mixins/emitter';
export default {
name: 'ElCheckbox',
mixins: [Emitter],
componentName: 'ElCheckbox',
data() {
@@ -56,6 +52,8 @@
};
},
inject: ['ElCheckboxGroup'],
computed: {
model: {
get() {
@@ -67,17 +65,16 @@
set(val) {
if (this.isGroup) {
let isLimitExceeded = false;
(this._checkboxGroup.min !== undefined &&
val.length < this._checkboxGroup.min &&
(this.group.min !== undefined &&
val.length < this.group.min &&
(isLimitExceeded = true));
(this._checkboxGroup.max !== undefined &&
val.length > this._checkboxGroup.max &&
(this.group.max !== undefined &&
val.length > this.group.max &&
(isLimitExceeded = true));
isLimitExceeded === false &&
this.dispatch('ElCheckboxGroup', 'input', [val]);
this.group.$emit('input', val);
} else if (this.value !== undefined) {
this.$emit('input', val);
} else {
@@ -96,21 +93,16 @@
}
},
group() {
return this.ElCheckboxGroup;
},
isGroup() {
let parent = this.$parent;
while (parent) {
if (parent.$options.componentName !== 'ElCheckboxGroup') {
parent = parent.$parent;
} else {
this._checkboxGroup = parent;
return true;
}
}
return false;
return !!this.group;
},
store() {
return this._checkboxGroup ? this._checkboxGroup.value : this.value;
return this.group ? this.group.value : this.value;
}
},
@@ -140,7 +132,7 @@
this.$emit('change', ev);
if (this.isGroup) {
this.$nextTick(_ => {
this.dispatch('ElCheckboxGroup', 'change', [this._checkboxGroup.value]);
this.group.$emit('change', this.group.value);
});
}
}