From 7c0b9140c713705ee4b25dc937ce402d0d57e7fd Mon Sep 17 00:00:00 2001 From: pooya parsa Date: Wed, 16 Mar 2022 23:49:30 +0100 Subject: [PATCH] feat(nuxt3): `watch` option for `useAsyncData` to auto refresh (#3722) --- docs/content/3.docs/1.usage/1.data-fetching.md | 2 ++ examples/use-async-data/app.vue | 6 +++++- examples/use-async-data/server/api/hello.js | 2 +- packages/nuxt3/src/app/composables/asyncData.ts | 15 +++++++++++++-- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/docs/content/3.docs/1.usage/1.data-fetching.md b/docs/content/3.docs/1.usage/1.data-fetching.md index 7fa4b563bd..b24e821810 100644 --- a/docs/content/3.docs/1.usage/1.data-fetching.md +++ b/docs/content/3.docs/1.usage/1.data-fetching.md @@ -18,6 +18,7 @@ const { pending: Ref, refresh: (force?: boolean) => Promise, error?: any + watch: WatchSource[] } = useAsyncData( key: string, handler: (ctx?: NuxtApp) => Promise, @@ -35,6 +36,7 @@ const { * _server_: whether to fetch the data on server-side (defaults to `true`) * _transform_: a function that can be used to alter `handler` function result after resolving * _pick_: only pick specified keys in this array from `handler` function result + * _watch_: watch reactive sources to auto refrash Under the hood, `lazy: false` uses `` to block the loading of the route before the data has been fetched. Consider using `lazy: true` and implementing a loading state instead for a snappier user experience. diff --git a/examples/use-async-data/app.vue b/examples/use-async-data/app.vue index 673d4689e7..86020c0f70 100644 --- a/examples/use-async-data/app.vue +++ b/examples/use-async-data/app.vue @@ -1,5 +1,6 @@