Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/watchArray.md
1---2category: Watch3---45# watchArray67Watch for an array with additions and removals.89## Usage1011Similar to `watch`, but provides the added and removed elements to the callback function. Pass `{ deep: true }` if the list is updated in place with `push`, `splice`, etc.1213```ts14import { watchArray } from '@vueuse/core'1516const list = ref([1, 2, 3])1718watchArray(list, (newList, oldList, added, removed) => {19console.log(newList) // [1, 2, 3, 4]20console.log(oldList) // [1, 2, 3]21console.log(added) // [4]22console.log(removed) // []23})2425onMounted(() => {26list.value = [...list.value, 4]27})28```2930## Type Declarations3132```ts33export declare type WatchArrayCallback<V = any, OV = any> = (34value: V,35oldValue: OV,36added: V,37removed: OV,38onCleanup: (cleanupFn: () => void) => void,39) => any40/**41* Watch for an array with additions and removals.42*43* @see https://vueuse.org/watchArray44*/45export declare function watchArray<46T,47Immediate extends Readonly<boolean> = false,48>(49source: WatchSource<T[]> | T[],50cb: WatchArrayCallback<T[], Immediate extends true ? T[] | undefined : T[]>,51options?: WatchOptions<Immediate>,52): WatchHandle53```54