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(Collapse): 手风琴模式下,modelValue 数据处理异常 #522

Merged
merged 1 commit into from
Dec 1, 2023

Conversation

1zumii
Copy link
Collaborator

@1zumii 1zumii commented Nov 30, 2023

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Docs
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

@@ -24,7 +24,7 @@ export default defineComponent({

const handleItemClick = (name: CollapseActiveName) => {
if (props.accordion) {
setActiveNames([activeNames.value[0] === name ? '' : name]);
setActiveNames(activeNames.value[0] === name ? '' : name);
} else {
const _activeNames = [...activeNames.value];
const index = _activeNames.indexOf(name);

Choose a reason for hiding this comment

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

这段代码补丁有以下几个问题和改进建议:

  1. 在代码的最后,数组索引index可能为-1,表示_activeNames中没有找到匹配的元素。在后续的代码逻辑中,没有对此情况进行处理。可以通过检查索引是否为-1来确保不会触发错误。

  2. 在条件语句中,使用[activeNames.value[0] === name ? '' : name]作为参数传递给setActiveNames函数。根据代码的上下文,setActiveNames函数期望接收一个数组类型(CollapseActiveName[]),而不是单个值。可以将该表达式修改为activeNames.value[0] === name ? [''] : [name]

  3. 可以优化第二个条件分支中的代码,避免创建新数组。在const _activeNames = [...activeNames.value];一行下面,可以直接使用activeNames.value.splice(index, 1);来删除匹配的元素,而无需创建新变量。

  4. 另外,代码的上下文中没有给出propsactiveNames的定义,无法判断其具体用途和结构。需要确保这些变量在当前模块或组件中按照预期进行声明和初始化。

这些是我对这个代码补丁的评论和建议。希望对你有所帮助!如果有其他问题,请随时提问。

@1zumii 1zumii changed the title fix(Collapse): 手风琴模式下,modelValue 为 string fix(Collapse): 手风琴模式下,modelValue 数据处理异常 Dec 1, 2023
- 调整 Collapse 文档调用 demo 组件语法
- 将 UseNormalModelReturn 移入 useModel 文件中
@ocean-gao ocean-gao merged commit 194428b into main Dec 1, 2023
1 check passed
@1zumii 1zumii deleted the fix-collapse-model-value branch December 1, 2023 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants