prefetchComponents
Nuxt 提供了一些实用程序,让你可以控制组件的预加载。
预加载组件会在后台下载代码,这是基于组件很可能用于渲染的假设,从而确保组件在用户请求时能够立即加载。该组件将被下载并缓存,以供将来使用,无需用户明确请求。
¥Prefetching component downloads the code in the background, this is based on the assumption that the component will likely be used for rendering, enabling the component to load instantly if and when the user requests it. The component is downloaded and cached for anticipated future use without the user making an explicit request for it.
使用 prefetchComponents
手动预加载已在 Nuxt 应用中全局注册的单个组件。默认情况下,Nuxt 将这些文件注册为异步组件。你必须使用 Pascal 大小写的组件名称。
¥Use prefetchComponents
to manually prefetch individual components that have been registered globally in your Nuxt app. By default Nuxt registers these as async components. You must use the Pascal-cased version of the component name.
await prefetchComponents('MyGlobalComponent')
await prefetchComponents(['MyGlobalComponent1', 'MyGlobalComponent2'])
当前实现的行为与
preloadComponents
完全相同,通过预加载组件而不是仅仅预取组件,我们正在努力改进这种行为。在服务器上,
prefetchComponents
将不起作用。