From f550c634e385ae4813cb1bee6af910176b2e6a76 Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 22 Jul 2021 19:53:16 +0800 Subject: [PATCH] fix(@vant/use): invalid watch source (#9095) --- packages/vant-use/src/useEventListener/index.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/vant-use/src/useEventListener/index.ts b/packages/vant-use/src/useEventListener/index.ts index b58e23314..e4ec9f5c5 100644 --- a/packages/vant-use/src/useEventListener/index.ts +++ b/packages/vant-use/src/useEventListener/index.ts @@ -1,4 +1,4 @@ -import { Ref, unref, onUnmounted, onDeactivated, watch } from 'vue'; +import { Ref, watch, isRef, unref, onUnmounted, onDeactivated } from 'vue'; import { onMountedOrActivated } from '../onMountedOrActivated'; import { inBrowser } from '../utils'; @@ -65,8 +65,10 @@ export function useEventListener( onDeactivated(() => remove(target)); onMountedOrActivated(() => add(target)); - watch(target, (val, oldVal) => { - remove(oldVal); - add(val); - }); + if (isRef(target)) { + watch(target, (val, oldVal) => { + remove(oldVal); + add(val); + }); + } }