mirror of https://github.com/ElemeFE/element
Form: remove emitter (#4532)
parent
72b1bc3c10
commit
fff7dddd94
|
@ -1,12 +1,16 @@
|
||||||
<script>
|
<script>
|
||||||
import Emitter from 'element-ui/src/mixins/emitter';
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ElCheckboxGroup',
|
name: 'ElCheckboxGroup',
|
||||||
|
|
||||||
componentName: 'ElCheckboxGroup',
|
componentName: 'ElCheckboxGroup',
|
||||||
|
|
||||||
mixins: [Emitter],
|
provide() {
|
||||||
|
return {
|
||||||
|
ElCheckboxGroup: this
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
inject: ['ElFormItem'],
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
value: {},
|
value: {},
|
||||||
|
@ -19,7 +23,7 @@
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
value(value) {
|
value(value) {
|
||||||
this.dispatch('ElFormItem', 'el.form.change', [value]);
|
this.ElFormItem.$emit('el.form.change', value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -40,13 +40,9 @@
|
||||||
</label>
|
</label>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import Emitter from 'element-ui/src/mixins/emitter';
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ElCheckbox',
|
name: 'ElCheckbox',
|
||||||
|
|
||||||
mixins: [Emitter],
|
|
||||||
|
|
||||||
componentName: 'ElCheckbox',
|
componentName: 'ElCheckbox',
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
|
@ -56,6 +52,8 @@
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
inject: ['ElCheckboxGroup'],
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
model: {
|
model: {
|
||||||
get() {
|
get() {
|
||||||
|
@ -67,17 +65,16 @@
|
||||||
set(val) {
|
set(val) {
|
||||||
if (this.isGroup) {
|
if (this.isGroup) {
|
||||||
let isLimitExceeded = false;
|
let isLimitExceeded = false;
|
||||||
(this._checkboxGroup.min !== undefined &&
|
(this.group.min !== undefined &&
|
||||||
val.length < this._checkboxGroup.min &&
|
val.length < this.group.min &&
|
||||||
(isLimitExceeded = true));
|
(isLimitExceeded = true));
|
||||||
|
|
||||||
(this._checkboxGroup.max !== undefined &&
|
(this.group.max !== undefined &&
|
||||||
val.length > this._checkboxGroup.max &&
|
val.length > this.group.max &&
|
||||||
(isLimitExceeded = true));
|
(isLimitExceeded = true));
|
||||||
|
|
||||||
isLimitExceeded === false &&
|
isLimitExceeded === false &&
|
||||||
this.dispatch('ElCheckboxGroup', 'input', [val]);
|
this.group.$emit('input', val);
|
||||||
|
|
||||||
} else if (this.value !== undefined) {
|
} else if (this.value !== undefined) {
|
||||||
this.$emit('input', val);
|
this.$emit('input', val);
|
||||||
} else {
|
} else {
|
||||||
|
@ -96,21 +93,16 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
group() {
|
||||||
|
return this.ElCheckboxGroup;
|
||||||
|
},
|
||||||
|
|
||||||
isGroup() {
|
isGroup() {
|
||||||
let parent = this.$parent;
|
return !!this.group;
|
||||||
while (parent) {
|
|
||||||
if (parent.$options.componentName !== 'ElCheckboxGroup') {
|
|
||||||
parent = parent.$parent;
|
|
||||||
} else {
|
|
||||||
this._checkboxGroup = parent;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
store() {
|
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);
|
this.$emit('change', ev);
|
||||||
if (this.isGroup) {
|
if (this.isGroup) {
|
||||||
this.$nextTick(_ => {
|
this.$nextTick(_ => {
|
||||||
this.dispatch('ElCheckboxGroup', 'change', [this._checkboxGroup.value]);
|
this.group.$emit('change', this.group.value);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import AsyncValidator from 'async-validator';
|
import AsyncValidator from 'async-validator';
|
||||||
import emitter from 'element-ui/src/mixins/emitter';
|
|
||||||
|
|
||||||
function noop() {}
|
function noop() {}
|
||||||
|
|
||||||
|
@ -49,7 +48,13 @@
|
||||||
|
|
||||||
componentName: 'ElFormItem',
|
componentName: 'ElFormItem',
|
||||||
|
|
||||||
mixins: [emitter],
|
provide() {
|
||||||
|
return {
|
||||||
|
ElFormItem: this
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
inject: ['ElForm'],
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
label: String,
|
label: String,
|
||||||
|
@ -93,11 +98,7 @@
|
||||||
return ret;
|
return ret;
|
||||||
},
|
},
|
||||||
form() {
|
form() {
|
||||||
var parent = this.$parent;
|
return this.ElForm;
|
||||||
while (parent.$options.componentName !== 'ElForm') {
|
|
||||||
parent = parent.$parent;
|
|
||||||
}
|
|
||||||
return parent;
|
|
||||||
},
|
},
|
||||||
fieldValue: {
|
fieldValue: {
|
||||||
cache: false,
|
cache: false,
|
||||||
|
@ -198,8 +199,7 @@
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
if (this.prop) {
|
if (this.prop) {
|
||||||
this.dispatch('ElForm', 'el.form.addField', [this]);
|
this.ElForm.$emit('el.form.addField', this);
|
||||||
|
|
||||||
let initialValue = this.fieldValue;
|
let initialValue = this.fieldValue;
|
||||||
if (Array.isArray(initialValue)) {
|
if (Array.isArray(initialValue)) {
|
||||||
initialValue = [].concat(initialValue);
|
initialValue = [].concat(initialValue);
|
||||||
|
@ -223,7 +223,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
this.dispatch('ElForm', 'el.form.removeField', [this]);
|
this.ElForm.$emit('el.form.removeField', this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -12,6 +12,12 @@
|
||||||
|
|
||||||
componentName: 'ElForm',
|
componentName: 'ElForm',
|
||||||
|
|
||||||
|
provide() {
|
||||||
|
return {
|
||||||
|
ElForm: this
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
model: Object,
|
model: Object,
|
||||||
rules: Object,
|
rules: Object,
|
||||||
|
|
Loading…
Reference in New Issue