From 7303e9ae86dbd526b3b00e4015993aa940d30d37 Mon Sep 17 00:00:00 2001 From: zkwolf Date: Thu, 25 Feb 2021 13:37:15 +0800 Subject: [PATCH] fix: select scorll in mobile (#3707) --- .../hooks/useMobileTouchMove.ts | 52 +++++++++++-------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/components/vc-virtual-list/hooks/useMobileTouchMove.ts b/components/vc-virtual-list/hooks/useMobileTouchMove.ts index f6c6a9374..d4eca84f7 100644 --- a/components/vc-virtual-list/hooks/useMobileTouchMove.ts +++ b/components/vc-virtual-list/hooks/useMobileTouchMove.ts @@ -1,5 +1,5 @@ import supportsPassive from '../../_util/supportsPassive'; -import { watch, Ref } from 'vue'; +import { watch, Ref, onMounted } from 'vue'; const SMOOTH_PTG = 14 / 15; @@ -80,28 +80,34 @@ export default function useMobileTouchMove( } }; - watch(inVirtual, val => { - listRef.value.removeEventListener( - 'touchstart', - onTouchStart, - supportsPassive - ? ({ - passive: false, - } as EventListenerOptions) - : false, + onMounted(() => { + watch( + inVirtual, + val => { + listRef.value.removeEventListener( + 'touchstart', + onTouchStart, + supportsPassive + ? ({ + passive: false, + } as EventListenerOptions) + : false, + ); + cleanUpEvents(); + clearInterval(interval); + if (val) { + listRef.value.addEventListener( + 'touchstart', + onTouchStart, + supportsPassive + ? ({ + passive: false, + } as EventListenerOptions) + : false, + ); + } + }, + { immediate: true }, ); - cleanUpEvents(); - clearInterval(interval); - if (val) { - listRef.value.addEventListener( - 'touchstart', - onTouchStart, - supportsPassive - ? ({ - passive: false, - } as EventListenerOptions) - : false, - ); - } }); }