Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1c12427

Browse files
fix(useResizeObserver): fix target is Ref Array (#4005)
Co-authored-by: Anthony Fu <[email protected]>
1 parent fe19c74 commit 1c12427

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

packages/core/useResizeObserver/index.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { tryOnScopeDispose } from '@vueuse/shared'
1+
import { type MaybeRefOrGetter, toValue, tryOnScopeDispose } from '@vueuse/shared'
22
import { computed, watch } from 'vue-demi'
3-
import type { MaybeComputedElementRef } from '../unrefElement'
3+
import type { MaybeComputedElementRef, MaybeElement } from '../unrefElement'
44
import { unrefElement } from '../unrefElement'
55
import { useSupported } from '../useSupported'
66
import type { ConfigurableWindow } from '../_configurable'
@@ -47,7 +47,7 @@ declare class ResizeObserver {
4747
* @param options
4848
*/
4949
export function useResizeObserver(
50-
target: MaybeComputedElementRef | MaybeComputedElementRef[],
50+
target: MaybeComputedElementRef | MaybeComputedElementRef[] | MaybeRefOrGetter<MaybeElement[]>,
5151
callback: ResizeObserverCallback,
5252
options: UseResizeObserverOptions = {},
5353
) {
@@ -62,10 +62,12 @@ export function useResizeObserver(
6262
}
6363
}
6464

65-
const targets = computed(() =>
66-
Array.isArray(target)
67-
? target.map(el => unrefElement(el))
68-
: [unrefElement(target)])
65+
const targets = computed(() => {
66+
const _targets = toValue(target)
67+
return Array.isArray(_targets)
68+
? _targets.map(el => unrefElement(el))
69+
: [unrefElement(_targets)]
70+
})
6971

7072
const stopWatch = watch(
7173
targets,

0 commit comments

Comments
 (0)