Skip to content

Commit 1b60606

Browse files
committed
fix: form-model throw error when use v-model and change at the same time #1971
1 parent 2dcaf5d commit 1b60606

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

components/_util/BaseMixin.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ export default {
2727
__emit() {
2828
// 直接调用listeners,底层组件不需要vueTool记录events
2929
const args = [].slice.call(arguments, 0);
30-
const filterEvent = [];
3130
const eventName = args[0];
32-
if (args.length && this.$listeners[eventName]) {
33-
if (filterEvent.includes(eventName)) {
34-
this.$emit(eventName, ...args.slice(1));
31+
const event = this.$listeners[eventName];
32+
if (args.length && event) {
33+
if (Array.isArray(event)) {
34+
for (let i = 0, l = event.length; i < l; i++) {
35+
event[i](...args.slice(1));
36+
}
3537
} else {
36-
this.$listeners[eventName](...args.slice(1));
38+
event(...args.slice(1));
3739
}
3840
}
3941
},

components/form-model/FormItem.jsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,22 @@ export default {
232232
let firstChildren = children[0];
233233
if (this.prop && this.autoLink && isValidElement(firstChildren)) {
234234
const originalEvents = getEvents(firstChildren);
235+
const originalBlur = originalEvents.blur;
236+
const originalChange = originalEvents.change;
235237
firstChildren = cloneElement(firstChildren, {
236238
on: {
237239
blur: (...args) => {
238-
originalEvents.blur && originalEvents.blur(...args);
240+
originalBlur && originalBlur(...args);
239241
this.onFieldBlur();
240242
},
241243
change: (...args) => {
242-
originalEvents.change && originalEvents.change(...args);
244+
if (Array.isArray(originalChange)) {
245+
for (let i = 0, l = originalChange.length; i < l; i++) {
246+
originalChange[i](...args);
247+
}
248+
} else if (originalChange) {
249+
originalChange(...args);
250+
}
243251
this.onFieldChange();
244252
},
245253
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,4 @@
211211
"lib/**/style/*",
212212
"*.less"
213213
]
214-
}
214+
}

0 commit comments

Comments
 (0)