diff --git a/src/guide/essentials/watchers.md b/src/guide/essentials/watchers.md index 6caa3652ea..9a290282cd 100644 --- a/src/guide/essentials/watchers.md +++ b/src/guide/essentials/watchers.md @@ -272,6 +272,42 @@ watch( + +## Once Watchers {#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. + +
+ +```js +export default { + watch: { + source: { + handler(newValue, oldValue) { + // when `source` changes, triggers only once + }, + once: true + } + } +} +``` + +
+ +
+ +```js +watch( + source, + (newValue, oldValue) => { + // when `source` changes, triggers only once + }, + { once: true } +) +``` + +
+
## `watchEffect()` \*\* {#watcheffect}