Skip to content

Commit b1b2b38

Browse files
authored
Update watchers.md
add once option description on watcher
1 parent 321453f commit b1b2b38

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/guide/essentials/watchers.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,41 @@ watch(
272272

273273
</div>
274274

275+
276+
## Once Watchers <sup class="vt-badge" data-text="3.4+" /> {#once-watchers}
277+
278+
Watcher's callback will execute whenever the watched source changes. If you want the callback to trigger only once when the source changes, use the `once: true` option.
279+
280+
<div class="options-api">
281+
282+
```js
283+
export default {
284+
watch: {
285+
source: {
286+
handler(newValue, oldValue) {
287+
// when `source` changes, triggers only once
288+
},
289+
once: true
290+
}
291+
}
292+
}
293+
```
294+
</div>
295+
296+
<div class="composition-api">
297+
298+
```js
299+
watch(
300+
source,
301+
(newValue, oldValue) => {
302+
// when `source` changes, triggers only once
303+
},
304+
{ once: true }
305+
)
306+
```
307+
308+
</div>
309+
275310
<div class="composition-api">
276311

277312
## `watchEffect()` \*\* {#watcheffect}

0 commit comments

Comments
 (0)