网页
综合
更新时间 2026-11-16 03:45:50
useAsyncData · Nuxt Composables v4
自动蜘蛛
nuxt.com
正文约 2156 字
Within your pages, components, and plugins you can use useAsyncData to get access to data that resolves asynchronously.
The built-in watch option allows automatically rerunning the fetcher function when any changes are detected.
You can use a computed ref, plain ref or a getter function as the key, allowing for dynamic data fetching that automatically updates when the key changes:
You can make your handler function abortable by using the signal provided in the second argument. This is useful for cancelling requests when they are no longer needed, such as when a user navigates away from a page. $fetch natively supports abort signals.
You can also pass an AbortSignal to the refresh/execute function to cancel individual requests manually.
If your handler function does not support abort signals, you can implement your own abort logic using the signal provided.
The handler signal will be aborted when:
getCachedData default:
This only caches data when experimental.payloadExtraction in nuxt.config is enabled.
When multiple useAsyncData calls use the same key, they share the same data, error, status, and pending refs. Keep the options listed below consistent across these calls.
The following options must be consistent across all calls with the same key:
The following options can differ without triggering warnings:
This composable returns a Promise that can be awaited, which makes it possible to use data directly within the <script setup> (i.e. a value will be present, instead of being undefined). You can also directly pull the values without awaiting the return value, in which case data can be undefined within <script setup> until the fetch completes.
In production, an error thrown on the server that is neither an HTTP error (such as one created with createError) nor a failed $fetch with a response status reaches error as a generic 500 error, so its message and data are not sent to the browser.
Access the reactive app config defined in the project.
useCookie is an SSR-friendly composable to read and write cookies.
Stay updated on new releases and features, guides, and community updates.
Copyright © 2016-2026 Nuxt - MIT License
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。