diff --git a/packages/shared/watchArray/index.ts b/packages/shared/watchArray/index.ts index 0045fbaa4f5..84da09f5fd6 100644 --- a/packages/shared/watchArray/index.ts +++ b/packages/shared/watchArray/index.ts @@ -9,15 +9,20 @@ export declare type WatchArrayCallback = (value: V, oldValue: * @see https://vueuse.org/watchArray */ export function watchArray = false>( - source: WatchSource, + source: WatchSource | T[], cb: WatchArrayCallback, options?: WatchOptions, ) { let oldList: T[] = options?.immediate ? [] - : [...(source instanceof Function ? source() : unref(source))] + : [...(source instanceof Function + ? source() + : Array.isArray(source) + ? source + : unref(source)), + ] - return watch(source, (newList, _, onCleanup) => { + return watch(source as WatchSource, (newList, _, onCleanup) => { const oldListRemains = new Array(oldList.length) const added: T[] = [] for (const obj of newList) {