• Watches one or more reactive data sources and invokes a callback function when the sources change.

    Example

    const count = ref(0)
    watch(count, (count) => {
    console.log(count)
    return () => console.log('cleanup')
    })
    count.value++

    Returns

    A function that can be called to stop the watch.

    See

    https://vuejs.org/api/reactivity-core.html#watch

    Type Parameters

    • T extends (object | WatchSource<unknown>)[]

    • Immediate extends Readonly<boolean> = false

    Parameters

    • sources: [...T[]]

      The watcher's source. The source can be one of the following: - A getter function that returns a value - A ref - A reactive object - ...or an array of the above.

    • cb: WatchCallback<MapSources<T, false>, MapSources<T, Immediate>>

      The callback that will be called when the source changes. It receives the new and old value(s) as arguments.

    • Optional options: WatchOptions<Immediate>

      Allows to control the watch's behaviour.

    Returns WatchStopHandle

  • Watches one or more reactive data sources and invokes a callback function when the sources change.

    Example

    const count = ref(0)
    watch(count, (count) => {
    console.log(count)
    return () => console.log('cleanup')
    })
    count.value++

    Returns

    A function that can be called to stop the watch.

    See

    https://vuejs.org/api/reactivity-core.html#watch

    Type Parameters

    • T extends readonly (object | WatchSource<unknown>)[]

    • Immediate extends Readonly<boolean> = false

    Parameters

    • source: T
    • cb: WatchCallback<MapSources<T, false>, MapSources<T, Immediate>>

      The callback that will be called when the source changes. It receives the new and old value(s) as arguments.

    • Optional options: WatchOptions<Immediate>

      Allows to control the watch's behaviour.

    Returns WatchStopHandle

  • Watches one or more reactive data sources and invokes a callback function when the sources change.

    Example

    const count = ref(0)
    watch(count, (count) => {
    console.log(count)
    return () => console.log('cleanup')
    })
    count.value++

    Returns

    A function that can be called to stop the watch.

    See

    https://vuejs.org/api/reactivity-core.html#watch

    Type Parameters

    • T

    • Immediate extends Readonly<boolean> = false

    Parameters

    • source: WatchSource<T>
    • cb: WatchCallback<T, Immediate extends true ? undefined | T : T>

      The callback that will be called when the source changes. It receives the new and old value(s) as arguments.

    • Optional options: WatchOptions<Immediate>

      Allows to control the watch's behaviour.

    Returns WatchStopHandle

  • Watches one or more reactive data sources and invokes a callback function when the sources change.

    Example

    const count = ref(0)
    watch(count, (count) => {
    console.log(count)
    return () => console.log('cleanup')
    })
    count.value++

    Returns

    A function that can be called to stop the watch.

    See

    https://vuejs.org/api/reactivity-core.html#watch

    Type Parameters

    • T extends object

    • Immediate extends Readonly<boolean> = false

    Parameters

    • source: T
    • cb: WatchCallback<T, Immediate extends true ? undefined | T : T>

      The callback that will be called when the source changes. It receives the new and old value(s) as arguments.

    • Optional options: WatchOptions<Immediate>

      Allows to control the watch's behaviour.

    Returns WatchStopHandle

Generated using TypeDoc