From 1b60606832e5888fa9f6fa99edb158e30633b297 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Sun, 29 Mar 2020 16:07:02 +0800 Subject: [PATCH] fix: form-model throw error when use v-model and change at the same time #1971 --- components/_util/BaseMixin.js | 12 +++++++----- components/form-model/FormItem.jsx | 12 ++++++++++-- package.json | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/components/_util/BaseMixin.js b/components/_util/BaseMixin.js index d15669e7d..d1e94aeda 100644 --- a/components/_util/BaseMixin.js +++ b/components/_util/BaseMixin.js @@ -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)); } } }, diff --git a/components/form-model/FormItem.jsx b/components/form-model/FormItem.jsx index 29164fafc..9dfba0ff7 100644 --- a/components/form-model/FormItem.jsx +++ b/components/form-model/FormItem.jsx @@ -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(); }, }, diff --git a/package.json b/package.json index bc1f13bea..92bbb9b36 100644 --- a/package.json +++ b/package.json @@ -211,4 +211,4 @@ "lib/**/style/*", "*.less" ] -} \ No newline at end of file +}