Skip to content

Commit 10065c7

Browse files
authored
docs: add once option on watcher (#2698)
* Update watchers.md add once option description on watcher * docs: column spacing
1 parent ab84422 commit 10065c7

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/guide/essentials/watchers.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,42 @@ 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+
295+
</div>
296+
297+
<div class="composition-api">
298+
299+
```js
300+
watch(
301+
source,
302+
(newValue, oldValue) => {
303+
// when `source` changes, triggers only once
304+
},
305+
{ once: true }
306+
)
307+
```
308+
309+
</div>
310+
275311
<div class="composition-api">
276312

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

0 commit comments

Comments
 (0)