perf(components): [select & select-v2] optimize performance (#15962)

closed #15932
This commit is contained in:
kooriookami 2024-02-28 12:41:56 +08:00 committed by GitHub
parent 2b68f465d1
commit 5cf6f775c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 20 deletions

View File

@ -669,17 +669,11 @@ const useSelect = (props: ISelectV2Props, emit) => {
return getValueKey(item) === getValueKey(props.modelValue)
})
} else {
if (props.modelValue.length > 0) {
states.hoveringIndex = Math.min(
...props.modelValue.map((selected) => {
return filteredOptions.value.findIndex((item) => {
return getValue(item) === selected
})
})
states.hoveringIndex = filteredOptions.value.findIndex((item) =>
props.modelValue.some(
(modelValue) => getValueKey(modelValue) === getValueKey(item)
)
} else {
states.hoveringIndex = -1
}
)
}
}

View File

@ -453,17 +453,11 @@ export const useSelect = (props: ISelectProps, emit) => {
return getValueKey(item) === getValueKey(states.selected)
})
} else {
if (states.selected.length > 0) {
states.hoveringIndex = Math.min(
...states.selected.map((selected) => {
return optionsArray.value.findIndex((item) => {
return getValueKey(item) === getValueKey(selected)
})
})
states.hoveringIndex = optionsArray.value.findIndex((item) =>
states.selected.some(
(selected) => getValueKey(selected) === getValueKey(item)
)
} else {
states.hoveringIndex = -1
}
)
}
}