Skip to content

Commit

Permalink
docs: add once option on watcher (#2698)
Browse files Browse the repository at this point in the history
* Update watchers.md

add once option description on watcher

* docs: column spacing
  • Loading branch information
KumJungMin committed Feb 17, 2024
1 parent ab84422 commit 10065c7
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/guide/essentials/watchers.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,42 @@ watch(

</div>


## Once Watchers <sup class="vt-badge" data-text="3.4+" /> {#once-watchers}

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.

<div class="options-api">

```js
export default {
watch: {
source: {
handler(newValue, oldValue) {
// when `source` changes, triggers only once
},
once: true
}
}
}
```

</div>

<div class="composition-api">

```js
watch(
source,
(newValue, oldValue) => {
// when `source` changes, triggers only once
},
{ once: true }
)
```

</div>

<div class="composition-api">

## `watchEffect()` \*\* {#watcheffect}
Expand Down

0 comments on commit 10065c7

Please sign in to comment.