Skip to content

Commit 190ab87

Browse files
committed
docs: update watch behavior adjustments
1 parent c05b8e6 commit 190ab87

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/guide/migration/introduction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ The following consists a list of breaking changes from 2.x:
9292
- [The `data` option from mixins is now merged shallowly](/guide/migration/data-option.html#mixin-merge-behavior-change)
9393
- [Attributes coercion strategy changed](/guide/migration/attribute-coercion.html)
9494
- [Some transition classes got a rename](/guide/migration/transition.html)
95-
- [Component watch option](/api/options-data.html#watch) and [instance method `$watch`](/api/instance-methods.html#watch) no longer supports dot-delimited string paths, use a computed function as the parameter instead.
95+
- When using [the `watch` option](/api/options-data.html#watch) to watch an array, the callback will only trigger when the array is replaced, and no longer trigger on array mutation. To trigger on mutation, the `deep` option must be specified. This is a side effect of more precise dependency tracking in Vue 3.
9696
- `<template>` tags with no special directives (`v-if/else-if/else`, `v-for`, or `v-slot`) are now treated as plain elements and will result in a native `<template>` element instead of rendering its inner content.
9797
- In Vue 2.x, application root container's `outerHTML` is replaced with root component template (or eventually compiled to a template, if root component has no template/render option). Vue 3.x now uses application container's `innerHTML` instead - this means the container itself is no longer considered part of the template.
9898

src/guide/reactivity-computed-watchers.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ An async function implicitly returns a Promise, but the cleanup function needs t
9393

9494
### Effect Flush Timing
9595

96-
Vue's reactivity system buffers invalidated effects and flushes them asynchronously to avoid unnecessary duplicate invocation when there are many state mutations happening in the same "tick". Internally, a component's `update` function is also a watched effect. When a user effect is queued, it is always invoked after all component `update` effects:
96+
Vue's reactivity system buffers invalidated effects and flushes them asynchronously to avoid unnecessary duplicate invocation when there are many state mutations happening in the same "tick". Internally, a component's `update` function is also a watched effect. When a user effect is queued, it is by default invoked **before** all component `update` effects:
9797

9898
```html
9999
<template>
@@ -120,7 +120,7 @@ Vue's reactivity system buffers invalidated effects and flushes them asynchronou
120120
In this example:
121121

122122
- The count will be logged synchronously on initial run.
123-
- When `count` is mutated, the callback will be called **after** the component has updated.
123+
- When `count` is mutated, the callback will be called **before** the component has updated.
124124

125125
Note the first run is executed before the component is mounted. So if you wish to access the DOM (or template refs) in a watched effect, do it in the `onMounted` hook:
126126

@@ -132,7 +132,7 @@ onMounted(() => {
132132
})
133133
```
134134

135-
In cases where a watcher effect needs to be re-run synchronously or before component updates, we can pass an additional `options` object with the `flush` option (default is `'post'`):
135+
In cases where a watcher effect needs to be re-run synchronously or after component updates, we can pass an additional `options` object with the `flush` option (default is `'pre'`):
136136

137137
```js
138138
// fire synchronously
@@ -145,13 +145,15 @@ watchEffect(
145145
}
146146
)
147147

148-
// fire before component updates
148+
// fire after component updates so you can access the updated DOM
149+
// Note: this will also defer the initial run of the effect until the
150+
// component's first render is finished.
149151
watchEffect(
150152
() => {
151153
/* ... */
152154
},
153155
{
154-
flush: 'pre'
156+
flush: 'post'
155157
}
156158
)
157159
```

0 commit comments

Comments
 (0)