Skip to content

Commit dd5ab86

Browse files
feat: Add watch changes (vuejs#314)
* feat(guide/migration): Added string parameter changes of 'watch' * fix(api/instance-methods): Updated the behavior with a string parameter * feat(api/instance-methods): Added an example for watching deep paths * feat(api/instance-methods): Increased the clarity of the example * feat(api/instance-methods): Clarified some terms It was clashing with 'complex expression' in the example * feat(api/instance-methods): Improve the clarity Co-authored-by: Natalia Tepluhina <[email protected]> * feat(api/instance-methods): Removed redundant comments Co-authored-by: Natalia Tepluhina <[email protected]> * feat(api/instance-methods): Clarified a term Increased the harmony by using an already introduced term Co-authored-by: Natalia Tepluhina <[email protected]>
1 parent f8a8612 commit dd5ab86

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/api/instance-methods.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
- **Usage:**
1616

17-
Watch an expression or a computed function on the Vue instance for changes. The callback gets called with the new value and the old value. The expression only accepts dot-delimited paths. For more complex expressions, use a function instead.
17+
Watch a reactive property or a computed function on the Vue instance for changes. The callback gets called with the new value and the old value for the given property. We can only pass top-level `data`, `prop`, or `computed` property name as a string. For more complex expressions or nested properties, use a function instead.
1818

1919
- **Example:**
2020

@@ -23,16 +23,28 @@
2323
data() {
2424
return {
2525
a: 1,
26-
b: 2
26+
b: 2,
27+
c: {
28+
d: 3,
29+
e: 4
30+
}
2731
}
2832
},
2933
created() {
30-
// keypath
34+
// top-level property name
3135
this.$watch('a', (newVal, oldVal) => {
3236
// do something
3337
})
3438

35-
// function
39+
// function for watching a single nested property
40+
this.$watch(
41+
() => this.c.d,
42+
(newVal, oldVal) => {
43+
// do something
44+
}
45+
)
46+
47+
// function for watching a complex expression
3648
this.$watch(
3749
// every time the expression `this.a + this.b` yields a different result,
3850
// the handler will be called. It's as if we were watching a computed

src/guide/migration/introduction.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ The following consists a list of breaking changes from 2.x:
3838
- Some transition classes got a rename:
3939
- `v-enter` -> `v-enter-from`
4040
- `v-leave` -> `v-leave-from`
41+
- [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
4142

4243
### Removed
4344

0 commit comments

Comments
 (0)