From 93b974ed0cf716cd43f8f33c4e810a311a9dd31b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E7=81=8F?= Date: Thu, 16 Sep 2021 17:09:59 +0800 Subject: [PATCH] Update picker.vue --- src/components/date-picker/picker.vue | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/components/date-picker/picker.vue b/src/components/date-picker/picker.vue index ed025e1d..8785d152 100644 --- a/src/components/date-picker/picker.vue +++ b/src/components/date-picker/picker.vue @@ -255,6 +255,7 @@ active: false }, internalFocus: false, + isValueNull: false // hack:解决 value 置为 null 时,$emit:input 不是 null }; }, computed: { @@ -789,6 +790,7 @@ this.$emit('on-open-change', state); }, value(val) { + if (val === null) this.isValueNull = true; this.internalValue = this.parseDate(val); }, open (val) { @@ -801,7 +803,15 @@ const newValue = JSON.stringify(now); const oldValue = JSON.stringify(before); const shouldEmitInput = newValue !== oldValue || typeof now !== typeof before; - if (shouldEmitInput) this.$emit('input', now); // to update v-model + // to update v-model + if (shouldEmitInput) { + if (this.isValueNull) { + this.isValueNull = false; + this.$emit('input', null); + } else { + this.$emit('input', now); + } + } }, }, mounted () {