Skip to content

Commit 9eae793

Browse files
committed
feat: add migration guide > watch
1 parent 1cc673a commit 9eae793

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/guide/migration/watch.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: Watch on Arrays
3+
badges:
4+
- breaking
5+
---
6+
7+
# {{ $frontmatter.title }} <MigrationBadges :badges="$frontmatter.badges" />
8+
9+
## Overview
10+
11+
- **BREAKING**: When watching an array, the callback will only trigger when the array is replaced. If you need to trigger on mutation, the `deep` option must be specified.
12+
13+
## 3.x Syntax
14+
15+
When using [the `watch` option](/api/options-data.html#watch) to watch an array, the callback will only trigger when the array is replaced. In other words, the watch callback will no longer be triggered on array mutation. To trigger on mutation, the `deep` option must be specified.
16+
17+
```js
18+
watch: {
19+
bookList: {
20+
handler(val, oldVal) {
21+
console.log('book list changed')
22+
},
23+
deep: true
24+
},
25+
}
26+
```
27+
28+
## Migration Strategy
29+
30+
If you rely on watching array mutations, add the `deep` property to ensure that your callback is triggered correctly.

0 commit comments

Comments
 (0)