diff --git a/packages/vant/src/picker/utils.ts b/packages/vant/src/picker/utils.ts index dfe2c660c..8953c97d4 100644 --- a/packages/vant/src/picker/utils.ts +++ b/packages/vant/src/picker/utils.ts @@ -49,7 +49,7 @@ export const isOptionExist = ( fields: Required, ) => value !== undefined && - !!options.find((option) => option[fields.value] === value); + options.some((option) => option[fields.value] === value); export function findOptionByValue( options: PickerOption[], diff --git a/packages/vant/src/tabbar-item/TabbarItem.tsx b/packages/vant/src/tabbar-item/TabbarItem.tsx index 6043bea02..c9557cfb2 100644 --- a/packages/vant/src/tabbar-item/TabbarItem.tsx +++ b/packages/vant/src/tabbar-item/TabbarItem.tsx @@ -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; diff --git a/packages/vant/src/tabs/Tabs.tsx b/packages/vant/src/tabs/Tabs.tsx index 0a1ec34ef..86f3ab9fe 100644 --- a/packages/vant/src/tabs/Tabs.tsx +++ b/packages/vant/src/tabs/Tabs.tsx @@ -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) => {