|
1 | 1 | # Instance Methods |
2 | 2 |
|
3 | | -## $watch |
| 3 | +## \$watch |
4 | 4 |
|
5 | 5 | - **Arguments:** |
6 | 6 |
|
|
59 | 59 | }) |
60 | 60 | ``` |
61 | 61 |
|
62 | | - When watched value is an Object or Array, any changes to its properties or elements won't trigger the watcher because they reference the same Object/Array: |
| 62 | + When watched value is an object or array, any changes to its properties or elements won't trigger the watcher because they reference the same object/array: |
63 | 63 |
|
64 | 64 | ```js |
65 | 65 | const app = Vue.createApp({ |
|
81 | 81 | }) |
82 | 82 | }, |
83 | 83 | methods: { |
84 | | - // These methods won't trigger a watcher because we changed only a property of Object/Array, |
85 | | - // not the Object/Array itself |
| 84 | + // These methods won't trigger a watcher because we changed only a property of object/array, |
| 85 | + // not the object/array itself |
86 | 86 | changeArticleText() { |
87 | 87 | this.article.text = 'Vue 3 is awesome' |
88 | 88 | }, |
89 | 89 | addComment() { |
90 | 90 | this.comments.push('New comment') |
91 | 91 | }, |
92 | 92 |
|
93 | | - // These methods will trigger a watcher because we replaced Object/Array completely |
| 93 | + // These methods will trigger a watcher because we replaced object/array completely |
94 | 94 | changeWholeArticle() { |
95 | 95 | this.article = { text: 'Vue 3 is awesome' } |
96 | 96 | }, |
|
121 | 121 |
|
122 | 122 | - **Option: deep** |
123 | 123 |
|
124 | | - To also detect nested value changes inside Objects, you need to pass in `deep: true` in the options argument. Note that you don't need to do so to listen for Array mutations. |
| 124 | + To also detect nested value changes inside Objects, you need to pass in `deep: true` in the options argument. Note that you don't need to do so to listen for array mutations. |
125 | 125 |
|
126 | 126 | ```js |
127 | 127 | vm.$watch('someObject', callback, { |
|
160 | 160 |
|
161 | 161 | ```js |
162 | 162 | let unwatch = null |
163 | | - |
| 163 | + |
164 | 164 | unwatch = vm.$watch( |
165 | 165 | 'value', |
166 | 166 | function() { |
|
176 | 176 | - **Option: flush** |
177 | 177 |
|
178 | 178 | The `flush` option allows for greater control over the timing of the callback. It can be set to `'pre'`, `'post'` or `'sync'`. |
179 | | - |
| 179 | + |
180 | 180 | The default value is `'pre'`, which specifies that the callback should be invoked before rendering. This allows the callback to update other values before the template runs. |
181 | | - |
| 181 | + |
182 | 182 | The value `'post'` can be used to defer the callback until after rendering. This should be used if the callback needs access to the updated DOM or child components via `$refs`. |
183 | 183 |
|
184 | 184 | If `flush` is set to `'sync'`, the callback will be called synchronously, as soon as the value changes. |
185 | 185 |
|
186 | 186 | For both `'pre'` and `'post'`, the callback is buffered using a queue. The callback will only be added to the queue once, even if the watched value changes multiple times. The interim values will be skipped and won't be passed to the callback. |
187 | | - |
| 187 | + |
188 | 188 | Buffering the callback not only improves performance but also helps to ensure data consistency. The watchers won't be triggered until the code performing the data updates has finished. |
189 | | - |
| 189 | + |
190 | 190 | `'sync'` watchers should be used sparingly, as they don't have these benefits. |
191 | 191 |
|
192 | 192 | For more information about `flush` see [Effect Flush Timing](../guide/reactivity-computed-watchers.html#effect-flush-timing). |
193 | 193 |
|
194 | 194 | - **See also:** [Watchers](../guide/computed.html#watchers) |
195 | 195 |
|
196 | | -## $emit |
| 196 | +## \$emit |
197 | 197 |
|
198 | 198 | - **Arguments:** |
199 | 199 |
|
|
266 | 266 | </div> |
267 | 267 | ` |
268 | 268 | }) |
269 | | - |
| 269 | + |
270 | 270 | app.mount('#emit-example-argument') |
271 | 271 | ``` |
272 | 272 |
|
273 | 273 | - **See also:** |
274 | 274 | - [`emits` option](./options-data.html#emits) |
275 | 275 | - [Emitting a Value With an Event](../guide/component-basics.html#emitting-a-value-with-an-event) |
276 | 276 |
|
277 | | -## $forceUpdate |
| 277 | +## \$forceUpdate |
278 | 278 |
|
279 | 279 | - **Usage:** |
280 | 280 |
|
281 | 281 | Force the component instance to re-render. Note it does not affect all child components, only the instance itself and child components with inserted slot content. |
282 | 282 |
|
283 | | -## $nextTick |
| 283 | +## \$nextTick |
284 | 284 |
|
285 | 285 | - **Arguments:** |
286 | 286 |
|
|
0 commit comments