From bb369d5a6694b61c62af374b0a0113bbff28a5bf Mon Sep 17 00:00:00 2001 From: winixt Date: Fri, 14 Jul 2023 16:33:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20select=20multiple=20=E6=94=AF=E6=8C=81un?= =?UTF-8?q?defined?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/_util/use/useModel.ts | 2 +- components/select/select.vue | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/components/_util/use/useModel.ts b/components/_util/use/useModel.ts index 12010013..b5f13200 100644 --- a/components/_util/use/useModel.ts +++ b/components/_util/use/useModel.ts @@ -78,7 +78,7 @@ export const useArrayModel = ( updateCurrentValue(value); return; } - const val = computedValue.value; + const val = computedValue.value || []; const index = val.indexOf(value); if (index !== -1) { val.splice(index, 1); diff --git a/components/select/select.vue b/components/select/select.vue index 399e142a..932acbf6 100644 --- a/components/select/select.vue +++ b/components/select/select.vue @@ -151,7 +151,7 @@ export default defineComponent({ const value: null | [] = props.multiple ? [] : null; if ( props.multiple - ? currentValue.value.length + ? currentValue.value?.length : currentValue.value !== null ) { updateCurrentValue(value); @@ -239,7 +239,7 @@ export default defineComponent({ const isSelect = (value: SelectValue) => { const selectVal = unref(currentValue); const optVal = unref(value); - if (selectVal === null) { + if (selectVal == null) { return false; } if (props.multiple) { @@ -252,7 +252,7 @@ export default defineComponent({ const selectVal = unref(currentValue); return ( props.multipleLimit > 0 && - props.multipleLimit === selectVal.length + props.multipleLimit === selectVal?.length ); }); @@ -329,7 +329,7 @@ export default defineComponent({ const option = getOption(newValue); selectedOptionsRef.value = option ? [option] : []; } else { - selectedOptionsRef.value = newValue + selectedOptionsRef.value = (newValue || []) .map((value: SelectValue) => { return getOption(value); }) @@ -417,7 +417,7 @@ export default defineComponent({ watch(isOpenedRef, () => { if (isOpenedRef.value) { if (props.multiple) { - if (currentValue.value.length > 0) { + if (currentValue.value?.length > 0) { hoverOptionValue.value = currentValue.value[0]; } } else if (!isNil(currentValue.value)) {