fix: form-model throw error when use v-model and change at the same time #1971

pull/1979/head
tangjinzhou 2020-03-29 16:07:02 +08:00
parent 2dcaf5d4ab
commit 1b60606832
3 changed files with 18 additions and 8 deletions

View File

@ -27,13 +27,15 @@ export default {
__emit() {
// 直接调用listeners底层组件不需要vueTool记录events
const args = [].slice.call(arguments, 0);
const filterEvent = [];
const eventName = args[0];
if (args.length && this.$listeners[eventName]) {
if (filterEvent.includes(eventName)) {
this.$emit(eventName, ...args.slice(1));
const event = this.$listeners[eventName];
if (args.length && event) {
if (Array.isArray(event)) {
for (let i = 0, l = event.length; i < l; i++) {
event[i](...args.slice(1));
}
} else {
this.$listeners[eventName](...args.slice(1));
event(...args.slice(1));
}
}
},

View File

@ -232,14 +232,22 @@ export default {
let firstChildren = children[0];
if (this.prop && this.autoLink && isValidElement(firstChildren)) {
const originalEvents = getEvents(firstChildren);
const originalBlur = originalEvents.blur;
const originalChange = originalEvents.change;
firstChildren = cloneElement(firstChildren, {
on: {
blur: (...args) => {
originalEvents.blur && originalEvents.blur(...args);
originalBlur && originalBlur(...args);
this.onFieldBlur();
},
change: (...args) => {
originalEvents.change && originalEvents.change(...args);
if (Array.isArray(originalChange)) {
for (let i = 0, l = originalChange.length; i < l; i++) {
originalChange[i](...args);
}
} else if (originalChange) {
originalChange(...args);
}
this.onFieldChange();
},
},

View File

@ -211,4 +211,4 @@
"lib/**/style/*",
"*.less"
]
}
}