fix(Picker): failed to update value in some cases (#11009)

This commit is contained in:
neverland 2022-09-04 21:00:18 +08:00 committed by GitHub
parent f60a3b840d
commit 0aac165d4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -245,10 +245,17 @@ export default defineComponent({
{ immediate: true } { immediate: true }
); );
// preserve last emitted model value
// when props.modelValue is updated by parent component,
// the new value should be compared with the last emitted value
let lastEmittedModelValue: Numeric[];
watch( watch(
() => props.modelValue, () => props.modelValue,
(newValues) => { (newValues) => {
if (!isSameValue(newValues, selectedValues.value)) { if (
!isSameValue(newValues, selectedValues.value) &&
!isSameValue(newValues, lastEmittedModelValue)
) {
selectedValues.value = newValues.slice(0); selectedValues.value = newValues.slice(0);
} }
}, },
@ -258,7 +265,8 @@ export default defineComponent({
selectedValues, selectedValues,
(newValues) => { (newValues) => {
if (!isSameValue(newValues, props.modelValue)) { if (!isSameValue(newValues, props.modelValue)) {
emit('update:modelValue', newValues.slice(0)); lastEmittedModelValue = newValues.slice(0);
emit('update:modelValue', lastEmittedModelValue);
} }
}, },
{ immediate: true } { immediate: true }