From b6a641798bdddded392d9bad344fee041689b305 Mon Sep 17 00:00:00 2001 From: hdx Date: Tue, 19 Nov 2024 17:46:43 +0800 Subject: [PATCH] =?UTF-8?q?swiper-list2:=20=E9=80=82=E9=85=8D=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/template/swiper-list2/swiper-list2.uvue | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pages/template/swiper-list2/swiper-list2.uvue b/pages/template/swiper-list2/swiper-list2.uvue index 05af2c19..9991f4ee 100644 --- a/pages/template/swiper-list2/swiper-list2.uvue +++ b/pages/template/swiper-list2/swiper-list2.uvue @@ -53,9 +53,11 @@ } }, onReady() { - this.tabScrollView = this.$refs['tabScroll'] as UniElement - this.swiperWidth = (this.$refs["swiper"] as UniElement).getBoundingClientRect().width - this.updateTabIndicator(this.swiperIndex, this.swiperIndex, 1) + this.tabScrollView = this.$refs['tabScroll'] as UniElement; + (this.$refs["swiper"] as UniElement).getBoundingClientRectAsync().then((res : DOMRect) => { + this.swiperWidth = res.width + this.updateTabIndicator(this.swiperIndex, this.swiperIndex, 1) + }); }, methods: { onTabClick(index : number) { @@ -124,7 +126,15 @@ // 滚动到水平中心位置 const target_x = lerpNumber(current_node.offsetLeft, move_to_node.offsetLeft, percentage) const center_x = target_x + move_to_node.offsetWidth / 2 - this.swiperWidth / 2 + // app 平台后续支持 scrollTo() + // #ifndef MP-WEIXIN this.tabScrollView!.scrollLeft = center_x + // #endif + // #ifdef MP-WEIXIN + this.tabScrollView!.scrollTo({ + left: center_x + }) + // #endif } } } -- GitLab