refactor: replace find method for improved readability (#13395)

This commit is contained in:
inottn
2025-03-16 07:56:14 +08:00
committed by GitHub
parent 567c3bf40b
commit ad085a4c99
3 changed files with 4 additions and 5 deletions

View File

@@ -49,7 +49,7 @@ export const isOptionExist = (
fields: Required<PickerFieldNames>,
) =>
value !== undefined &&
!!options.find((option) => option[fields.value] === value);
options.some((option) => option[fields.value] === value);
export function findOptionByValue(
options: PickerOption[],

View File

@@ -59,7 +59,7 @@ export default defineComponent({
const { $route } = vm;
const { to } = props;
const config = isObject(to) ? to : { path: to };
return !!$route.matched.find((val) => {
return $route.matched.some((val) => {
const pathMatched = 'path' in config && config.path === val.path;
const nameMatched = 'name' in config && config.name === val.name;
return pathMatched || nameMatched;

View File

@@ -267,12 +267,11 @@ export default defineComponent({
name: Numeric,
skipScrollIntoView?: boolean,
) => {
const matched = children.find(
const index = children.findIndex(
(tab, index) => getTabName(tab, index) === name,
);
const index = matched ? children.indexOf(matched) : 0;
setCurrentIndex(index, skipScrollIntoView);
setCurrentIndex(index === -1 ? 0 : index, skipScrollIntoView);
};
const scrollToCurrentContent = (immediate = false) => {