Skip to content

Commit

Permalink
fix(useEventListener): support component target (#1408)
Browse files Browse the repository at this point in the history
  • Loading branch information
okxiaoliang4 committed Mar 16, 2022
1 parent 1ee0ae0 commit 981c651
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/core/useEventListener/index.ts
@@ -1,6 +1,8 @@
import type { Fn, MaybeRef } from '@vueuse/shared'
import { isString, noop, tryOnScopeDispose } from '@vueuse/shared'
import { unref, watch } from 'vue-demi'
import { watch } from 'vue-demi'
import type { MaybeElementRef } from '../unrefElement'
import { unrefElement } from '../unrefElement'
import { defaultWindow } from '../_configurable'

interface InferEventTarget<Events> {
Expand Down Expand Up @@ -99,7 +101,7 @@ export function useEventListener(...args: any[]) {
let cleanup = noop

const stopWatch = watch(
() => unref(target),
() => unrefElement(target as unknown as MaybeElementRef),
(el) => {
cleanup()
if (!el)
Expand Down

0 comments on commit 981c651

Please sign in to comment.