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); + }); + } }