From e445befc2a6712cabf6926f6a1390f327153cb1a Mon Sep 17 00:00:00 2001 From: lizhen21 Date: Mon, 28 Oct 2024 12:25:28 +0800 Subject: [PATCH] =?UTF-8?q?fix(tabBarItem):=20issues=EF=BC=9ATabbarItem=20?= =?UTF-8?q?component=20in=20the=20route=20mode=20fails=20to=20bind=20with?= =?UTF-8?q?=20v-model?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/vant/src/tabbar-item/TabbarItem.tsx | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/vant/src/tabbar-item/TabbarItem.tsx b/packages/vant/src/tabbar-item/TabbarItem.tsx index 6043bea027e..e2f18de52b4 100644 --- a/packages/vant/src/tabbar-item/TabbarItem.tsx +++ b/packages/vant/src/tabbar-item/TabbarItem.tsx @@ -59,11 +59,17 @@ export default defineComponent({ const { $route } = vm; const { to } = props; const config = isObject(to) ? to : { path: to }; - return !!$route.matched.find((val) => { - const pathMatched = 'path' in config && config.path === val.path; - const nameMatched = 'name' in config && config.name === val.name; - return pathMatched || nameMatched; - }); + const pathMatched = + 'path' in config && + $route.matched.some((val) => config.path === val.path); + const nameMatched = + 'name' in config && + $route.matched.some((val) => config.name === val.name); + const isActive = pathMatched || nameMatched; + if (isActive) { + parent.setActive(props.name ?? index.value, () => {}); + } + return isActive; } return (props.name ?? index.value) === modelValue;