SKILL

nuxt4-patterns

Nuxt 4 application patterns covering hydration safety, performance optimization, route rules, lazy loading, and SSR-safe data fetching using useFetch and useAsyncData.

Translation reviewed
Read the original Chinese text

Nuxt 4 应用模式,涵盖水合安全、性能优化、路由规则、懒加载,以及使用 useFetch 和 useAsyncData 进行 SSR 安全的数据获取。

Target: Vue / Nuxt. Automatically collected · unverified.

Excerpt from the author’s documentation

Extracted from a fixed version of SKILL.md in its original language. This is the author’s documentation; installation, compatibility and runtime results have not been verified by this site.

Read the original Chinese text

Topics in the source

  • Nuxt 4 模式
  • 何时激活
  • 水合安全性
  • 数据获取
  • 路由规则
  • 懒加载与性能
  • 检查清单

在构建或调试具有 SSR、混合渲染、路由规则或页面级数据获取的 Nuxt 4 应用时使用。 服务器 HTML 与客户端状态之间的水合不匹配 路由级别的渲染决策,例如预渲染、SWR、ISR 或仅客户端部分 围绕懒加载、延迟水合或有效负载大小的性能工作 使用 useFetch、useAsyncData 或 $fetch 进行页面或组件数据获取 与路由参数、中间件或 SSR/客户端差异相关的 Nuxt 路由问题 保持首次渲染是确定性的。不要将 Date.now()、Math.random()、仅限浏览器的 API 或存储读取直接放入 SSR 渲染的模板状态中。 当服务器无法生成相同标记时,将仅限浏览器的逻辑移到 onMounted()、import.meta.client、ClientOnly 或 .client.vue 组件后面。 使用 Nuxt 的 useRoute() 组合式函数,而不是来自 vue-router 的那个。 不要使用 route.fullPath 来驱动 SSR 渲染的标记。URL 片段是仅客户端的,这可能导致水合不匹配。 将 ssr: false 视为真正仅限浏览器区域的逃生舱口,而不是解决不匹配的默认修复方法。 在页面和组件中,优先使用 await useFetch() 进行 SSR 安全的 API 读取。它将服务器获取的数据转发到 Nuxt 有效负载中,并避免在水合时进行第二次获取。 当数据获取器不是简单的 $fetch() 调用,或者需要自定义键,或者正在组合多个异步源时,使用 useAsyncData()。 为 useAsyncData() 提供一个稳定的键以重用缓存并实现可预测的刷新行为。 保持 useAsyncData() 处理程序无副作用。它们可能在 SSR 和水合期间运行。 将 $fetch() 用于用户触发的写入或仅客户端操作,而不是应该从 SSR 水合而来的顶级页面数据。 对于不应阻塞导航的非关键数据,使用 lazy: true、useLazyFetch() 或 useLazyAsyncData()。在 UI 中处理 status === 'pending'。 仅对 SEO 或首次绘制不需要的数据使用 server: false。 使用 pick 修剪有效负载大小,并在不需要深层响应性时优先使用较浅的有效负载。 在 nuxt.config.ts 中优先使用 routeRules 来定义渲染和缓存策略: prerender:在构建时生成静态 HTML swr:提供缓存内容并在后台重新验证 isr:在支持的平台上进行增量静态再生 ssr: false:客户端渲染的路由 cache 或 redirect:Nitro 级别的响应行为 按路由组选择路由规则,而非全局设置。营销页面、产品目录、仪表板和 API 通常需要不同的策略。

This is an excerpt. Refer to the complete source and its current requirements.

Source repository
affaan-m/ECC
Source file
docs/zh-CN/skills/nuxt4-patterns/SKILL.md
Fixed revision
d2ef2680594f9a17526a6e1a2e18b3d242c5d17b
Read the complete original documentation ↗

Requirements

  • Only the author’s Skill metadata is included. Read the full instructions to check dependencies, licensing and conditions of use.

A small first task

先阅读原作者说明,再决定是否在自己的 AI 工具中使用。

Instructions for your AI tool

Author documentation is not live verification by this site. Without evidence, we do not mark a resource as compatible, safe or free.

Sources and evidence

This record was collected automatically. Its documentation, suitability and runtime behavior have not been manually verified.

Author: affaan-m/ECC · original repository metadata. Documentation review: Not reviewed. Last source check: 2026-11-09T15:01:42.484Z.

Categories are inferred from names, descriptions and paths. They do not establish compatibility.

License and attribution

MIT. Third-party content and copyright remain with their authors. Refer to the original license and terms.

Original license ↗

Synchronization, copying and user-reported success do not mark a resource as runtime-tested.

Limitations and notes

  • Collecting metadata does not mean this site has installed, adapted, runtime-tested or security-reviewed the resource.