Skip to content
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 兼容 options 为 null 的场景 #341

Merged
merged 1 commit into from
Jul 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion components/select/select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export default defineComponent({
};

const baseOptions = computed(() => {
const allOptions = [...childOptions, ...props.options];
const allOptions = [...childOptions, ...(props.options || [])];
return allOptions.map((option) => {
return {
...option,
Expand Down Expand Up @@ -428,6 +428,7 @@ export default defineComponent({
hoverOptionValue.value = option.value;
}
} else {
// eslint-disable-next-line no-undefined
hoverOptionValue.value = undefined;
}
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这段代码看起来主要是在一个Vue组件中进行的修改。以下是对每个部分的简要代码审查:

  • 从第185行开始,使用了computed属性计算baseOptions。这个属性将childOptionsprops.options数组合并到一起,并使用.map()方法对每个选项进行转换处理。有一个改动,就是对props.options增加了一个空数组的默认值,以避免在props.options为undefined时出现问题。

  • 从第428行开始,在鼠标悬浮事件处理函数中,如果isHoverEnabled为true,则设置hoverOptionValue.value为当前选项的值。在else语句中,通过注释关闭了eslint-disable-next-line no-undefined警告,并将hoverOptionValue.value设置为undefined。

总体来说,这个代码补丁并没有明显的错误风险。以下是一些建议的改进点:

  1. 可能考虑添加注释或文档说明,特别是关于prop(如options)期望值和用途的描述。

  2. 如果遵循团队编码规范,请确保在整个项目中使用一致的缩进和代码风格。

  3. 考虑增加错误处理,例如在props.options不是数组时给出相应的警告或错误提示。

  4. 根据具体需求,可能需要为childOptionsprops.options提供更好的默认值,以便在没有数据时有更合适的显示。

以上是对给出代码补丁的简要审查和改进建议。如果还有其他问题,请随时提问。

Expand Down