Skip to content

watchOnce

Category
Export Size
123 B
Last Changed
3 months ago

Shorthand for watching value with { once: true }. Once the callback fires once, the watcher will be stopped. See Vue's docs for full details.

Usage

Similar to watch, but with { once: true }

ts
import { 
watchOnce
} from '@vueuse/core'
watchOnce
(source, () => {
// triggers only once
console
.
log
('source changed!')
})

Type Declarations

ts
export declare function 
watchOnce
<
T
extends
Readonly
<
WatchSource
<unknown>[]>>(
source
: [...
T
],
cb
:
WatchCallback
<
MapSources
<
T
>,
MapOldSources
<
T
, true>>,
options
?:
Omit
<
WatchOptions
<true>, "once">,
):
WatchStopHandle
export declare function
watchOnce
<
T
>(
source
:
WatchSource
<
T
>,
cb
:
WatchCallback
<
T
,
T
| undefined>,
options
?:
Omit
<
WatchOptions
<true>, "once">,
):
WatchStopHandle
export declare function
watchOnce
<
T
extends object>(
source
:
T
,
cb
:
WatchCallback
<
T
,
T
| undefined>,
options
?:
Omit
<
WatchOptions
<true>, "once">,
):
WatchStopHandle

Source

SourceDocs

Contributors

Anthony Fu
Anthony Fu
Fernando Fernández
Howard Guo
Valery
vaakian X
lvjiaxuan
lvjiaxuan
HG
webfansplz

Changelog

v13.2.0 on
08f7d - feat: use vue's native once behaviour (#4750)
v12.0.0-beta.1 on
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
v10.6.0 on
bb0a7 - feat: return function for manual watcher stopping (#3475)

Released under the MIT License.

Build faster with AI
New Masterclass to help you leverage AI in your Vue workflow
Get Early Access