From 675e5ac75fa79354cdf35478edf9055b7e7b2882 Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Sun, 9 Jan 2022 18:09:58 +0300 Subject: [PATCH] Add watchParam info --- content/en/docs/3.features/4.data-fetching.md | 8 +++++ .../7.components-glossary/11.watchparam.md | 31 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 content/en/docs/7.components-glossary/11.watchparam.md diff --git a/content/en/docs/3.features/4.data-fetching.md b/content/en/docs/3.features/4.data-fetching.md index 8bc34df35a..a42bc5ca2c 100644 --- a/content/en/docs/3.features/4.data-fetching.md +++ b/content/en/docs/3.features/4.data-fetching.md @@ -272,3 +272,11 @@ The `asyncData` method is not called on query string changes by default. If ::alert{type="next"} Learn more about the [watchQuery property](/docs/components-glossary/watchquery) and see the list of available [keys in context](/docs/concepts/context-helpers). :: + +### Listening to param changes + +By default every route param change will call `asyncData`. If you want to disable it, set up `watchParam: false`. For example it may be helpfull to disable `state` reset. + +::alert{type="next"} +Learn more about the [watchParam property](/docs/components-glossary/watchparam). +:: diff --git a/content/en/docs/7.components-glossary/11.watchparam.md b/content/en/docs/7.components-glossary/11.watchparam.md new file mode 100644 index 0000000000..a040d888e5 --- /dev/null +++ b/content/en/docs/7.components-glossary/11.watchparam.md @@ -0,0 +1,31 @@ +--- +title: 'The watchParam Property' +description: Watch param change and execute component methods on change (asyncData, fetch(context)) +navigation.title: WatchParam Property +category: components-glossary +--- +# The watchParam property + +Watch param change and execute component methods on change (asyncData, fetch(context)) + +--- + +- **Type:** `Boolean` (default: `undefined`) + +Use the `watchParam` key to set up a watcher for route params. If the params change, asyncData and fetch(context) will be called. Watching is enabled by default. + +If you want to disable watching for params, set `watchParam: false`. + +```js +export default { + watchParam: false +} +``` + +::alert{type="info"} +By default `nuxt.js` reset _page_ component `data` state after route param change, you can use `watchParam: false` to disable this behaviour. +:: + +::alert{type="warning"} +**Warning**: The new `fetch` hook introduced in 2.12 is not affected by `watchParam`. For more information see [listening to query string changes](/docs/features/data-fetching#the-fetch-hook) for params is the same. +::