From fc3f745bf45c70ec457a832758160e2e8e5a7b51 Mon Sep 17 00:00:00 2001 From: "Baorong\\Baorong" Date: Mon, 22 Apr 2024 11:12:40 +0800 Subject: [PATCH] fix tabs: tabRect could be undefined --- packages/tabs/index.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/tabs/index.ts b/packages/tabs/index.ts index 6968995bf..039436f39 100644 --- a/packages/tabs/index.ts +++ b/packages/tabs/index.ts @@ -276,13 +276,15 @@ VantComponent({ getRect(this, '.van-tabs__nav'), ]).then(([tabRects, navRect]) => { const tabRect = tabRects[currentIndex]; - const offsetLeft = tabRects + if (tabRect) { + const offsetLeft = tabRects .slice(0, currentIndex) .reduce((prev, curr) => prev + curr.width, 0); - this.setData({ - scrollLeft: offsetLeft - (navRect.width - tabRect.width) / 2, - }); + this.setData({ + scrollLeft: offsetLeft - (navRect.width - tabRect.width) / 2, + }); + } if (!scrollWithAnimation) { nextTick(() => {