From 4bb8a099c312e1e08d3fb089d4ca467dbd51d0f2 Mon Sep 17 00:00:00 2001 From: zhenyuWang <13641039885@163.com> Date: Thu, 26 Oct 2023 17:01:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Element.setAttribute=20=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/template/custom-tab-bar/custom-tab-bar-tab1.uvue | 2 +- pages/template/long-list/long-list.uvue | 6 ++++-- pages/template/long-list2/long-list2.uvue | 4 +++- pages/template/swiper-list/swiper-list.uvue | 4 +++- pages/template/swiper-list2/swiper-list2.uvue | 4 +++- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/pages/template/custom-tab-bar/custom-tab-bar-tab1.uvue b/pages/template/custom-tab-bar/custom-tab-bar-tab1.uvue index 8d399308..c0b2f152 100644 --- a/pages/template/custom-tab-bar/custom-tab-bar-tab1.uvue +++ b/pages/template/custom-tab-bar/custom-tab-bar-tab1.uvue @@ -35,7 +35,7 @@ uni.$emit('tabchange', e.detail.scrollTop) }, scrollTop(top : number) { - (this.$refs["listView"] as Element).setAttribute('scrollTop', top) + (this.$refs["listView"] as Element).scrollTop = top } } } diff --git a/pages/template/long-list/long-list.uvue b/pages/template/long-list/long-list.uvue index 97f1c131..4c95a759 100644 --- a/pages/template/long-list/long-list.uvue +++ b/pages/template/long-list/long-list.uvue @@ -205,8 +205,10 @@ this.$indicatorNode?.style?.setProperty('transform', `translateX(${x}px) scaleX(${indicator_line_w})`) // 滚动到水平中心位置 - const scroll_x = x - this.$swiperWidth / 2 - this.$tabScrollView?.setAttribute('scrollLeft', scroll_x) + const scroll_x = x - this.$swiperWidth / 2 + if(this.$tabScrollView !== null){ + this.$tabScrollView!.scrollLeft = scroll_x + } }, initSwiperItemData(index : number) { if (!this.swiperList[index].preload) { diff --git a/pages/template/long-list2/long-list2.uvue b/pages/template/long-list2/long-list2.uvue index 78369962..bd077d3b 100644 --- a/pages/template/long-list2/long-list2.uvue +++ b/pages/template/long-list2/long-list2.uvue @@ -201,7 +201,9 @@ // 滚动到水平中心位置 const scroll_x = x - this.$swiperWidth / 2 - this.$tabScrollView?.setAttribute('scrollLeft', scroll_x) + if(this.$tabScrollView !== null){ + this.$tabScrollView!.scrollLeft = scroll_x + } }, initSwiperItemData(index : number) { if (!this.swiperList[index].preload) { diff --git a/pages/template/swiper-list/swiper-list.uvue b/pages/template/swiper-list/swiper-list.uvue index cd40b452..e7dcdabe 100644 --- a/pages/template/swiper-list/swiper-list.uvue +++ b/pages/template/swiper-list/swiper-list.uvue @@ -164,7 +164,9 @@ // 滚动到水平中心位置 const scroll_x = x - this.$swiperWidth / 2 - this.$tabScrollView?.setAttribute('scrollLeft', scroll_x) + if(this.$tabScrollView !== null){ + this.$tabScrollView!.scrollLeft = scroll_x + } } } } diff --git a/pages/template/swiper-list2/swiper-list2.uvue b/pages/template/swiper-list2/swiper-list2.uvue index 18b82f54..ded942b7 100644 --- a/pages/template/swiper-list2/swiper-list2.uvue +++ b/pages/template/swiper-list2/swiper-list2.uvue @@ -122,7 +122,9 @@ // 滚动到水平中心位置 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 - this.$tabScrollView?.setAttribute('scrollLeft', center_x) + if(this.$tabScrollView !== null){ + this.$tabScrollView!.scrollLeft = center_x + } } } } -- GitLab