Skip to content

Commit

Permalink
docs: directly watch a specific param
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Apr 27, 2021
1 parent 85081ce commit 70bebfc
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions docs/guide/advanced/composition-api.md
Expand Up @@ -26,7 +26,7 @@ export default {
}
```

The `route` object is a reactive object, so any of its properties can be watched and you should **avoid watching the whole `route`** object:
The `route` object is a reactive object, so any of its properties can be watched and you should **avoid watching the whole `route`** object. In most scenarios, you should directly watch the param you are expecting to change

```js
import { useRoute } from 'vue-router'
Expand All @@ -38,9 +38,9 @@ export default {

// fetch the user information when params change
watch(
() => route.params,
async newParams => {
userData.value = await fetchUser(newParams.id)
() => route.params.id,
async newId => {
userData.value = await fetchUser(newId)
}
)
},
Expand Down

0 comments on commit 70bebfc

Please sign in to comment.