From f608710d267b7decd34635e6234c7d181b67acc0 Mon Sep 17 00:00:00 2001 From: zkwolf Date: Tue, 23 Feb 2021 22:29:24 +0800 Subject: [PATCH] fix: select scorll in mobile --- .../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 f6c6a93745..d4eca84f7b 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, - ); - } }); }