Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Document that watchQuery can be a function #1661

Merged
merged 1 commit into from
Oct 19, 2019
Merged
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
14 changes: 13 additions & 1 deletion en/api/pages-watchquery.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Watch query strings and execute component methods on change (asyncD
---

> Watch query strings and execute component methods on change (asyncData, fetch, validate, layout, ...)
- **Type:** `Boolean` or `Array` (default: `[]`)
- **Type:** `Boolean` or `Array` or `Function` (default: `[]`)

Use the `watchQuery` key to set up a watcher for query strings. If the defined strings change, all component methods (asyncData, fetch, validate, layout, ...) will be called. Watching is disabled by default to improve performance.

Expand All @@ -15,3 +15,15 @@ export default {
watchQuery: ['page']
}
```

You can also use the function `watchQuery(newQuery, oldQuery)` to have more refined watchers.

```js
export default {
watchQuery (newQuery, oldQuery) {
// Only execute component methods if the old query string contained `bar`
// and the new query string contains `foo`
return newQuery.foo && oldQuery.bar
}
}
```