Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update WATCH_ARRAY recommendations to use deep: 1 #70

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/breaking-changes/watch.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ badges:
## Overview

- **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.
- In Vue 3.5+, `deep: 1` should be used, which will trigger on array replacement and array mutation.
- Prior to Vue 3.5, `deep: true` can be used, but it will also trigger on deep changes in array elements.

## 3.x Syntax

Expand All @@ -20,11 +22,18 @@ watch: {
handler(val, oldVal) {
console.log('book list changed')
},
deep: true
deep: 1 // Vue 3.5+
deep: true // Vue 3.0 - 3.4
},
}
```

:::warning

In versions prior to Vue 3.5, watches don't allow setting the [max traversal depth](https://vuejs.org/guide/essentials/watchers.html#deep-watchers), so you're stuck with `deep: true`, which will also trigger the callback on deep modification of array elements.

:::

## Migration Strategy

If you rely on watching array mutations, add the `deep` option to ensure that your callback is triggered correctly.
Expand Down