From fffcf3a9122ea3e3fc56b21e19abae79a93e8d97 Mon Sep 17 00:00:00 2001 From: star knight <64941905+starknt@users.noreply.github.com> Date: Tue, 23 Apr 2024 13:09:26 +0800 Subject: [PATCH] fix: horizontal scrolling invalid when reload component (#642) --- src/components/HorizontalScrollView.vue | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/HorizontalScrollView.vue b/src/components/HorizontalScrollView.vue index ca713419..a6cea184 100644 --- a/src/components/HorizontalScrollView.vue +++ b/src/components/HorizontalScrollView.vue @@ -7,11 +7,14 @@ const scrollListWrap = ref() as Ref // const showRightMask = ref(false) const showScrollMask = ref(true) -watch(() => settings.value.enableHorizontalScrolling, (newValue) => { - if (newValue) - scrollListWrap.value.addEventListener('wheel', handleMouseScroll) +watch([() => settings.value.enableHorizontalScrolling, scrollListWrap], ([enableHorizontalScrolling, scrollListWrap]) => { + if (!scrollListWrap) + return + + if (enableHorizontalScrolling) + scrollListWrap.addEventListener('wheel', handleMouseScroll) else - scrollListWrap.value.removeEventListener('wheel', handleMouseScroll) + scrollListWrap.removeEventListener('wheel', handleMouseScroll) }) onMounted(() => {