-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: select multiple 支持undefined #345
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这段代码补丁主要涉及到一个 Vue 组件的更新。下面是对每个修改处的问题和可能的改进建议:
总体而言,这些修改都有助于代码的健壮性和可读性。操作符的调整以及对可能为空的值进行处理都是很好的实践。 |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
以下是您提供的代码补丁,请允许我对其进行简要的代码审查。欢迎指出任何潜在的错误风险和改进建议:
@@ -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);
代码审查意见:
const val = computedValue.value;
将没有值的情况留给了后面的逻辑处理。通过将其修改为const val = computedValue.value || [];
,如果computedValue.value
为假值(如null
或undefined
),则会为val
提供一个默认值[]
。这样做可以防止报错或异常行为,并确保代码正常运行。请注意,以上反馈基于我能够理解的代码片段,并且只能提供相对概括的回答。对于准确的评估,建议您查看完整的代码并运行测试。