app/app.vue
Component Names
If you have a component in nested directories such as:For clarity, we recommend that the component’s filename matches its name. So, in the example above, you could rename
Button.vue to be BaseFooButton.vue.pathPrefix option to false using extended form of the configuration object:
nuxt.config.ts
~/components/Some/MyComponent.vue will be usable as <MyComponent> and not <SomeMyComponent>.
Dynamic Components
If you want to use the Vue<component :is="someComputedComponent"> syntax, you need to use the resolveComponent helper provided by Vue or import the component directly from #components and pass it into is prop.
For example:
app/pages/index.vue
If you are using
resolveComponent to handle dynamic components, make sure not to insert anything but the name of the component, which must be a literal string and not be or contain a variable. The string is statically analyzed at the compilation step.Dynamic Imports
To dynamically import a component (also known as lazy-loading a component) all you need to do is add theLazy prefix to the component’s name. This is particularly useful if the component is not always needed.
By using the Lazy prefix you can delay loading the component code until the right moment, which can be helpful for optimizing your JavaScript bundle size.
app/pages/index.vue
Delayed Hydration
Lazy components are great for controlling the chunk sizes in your app, but they don’t always enhance runtime performance, as they still load eagerly unless conditionally rendered. In real-world applications, some pages may include a lot of content and a lot of components, and most of the time not all of them need to be interactive as soon as the page is loaded. In order to optimize your app, you may want to delay the hydration of some components until they’re visible, or until the browser is done with more important tasks. Nuxt supports this using lazy (or delayed) hydration, allowing you to control when components become interactive.Hydration Strategies
Nuxt provides a range of built-in hydration strategies. Only one strategy can be used per lazy component.Any prop change on a lazily hydrated component will trigger hydration immediately. (e.g., changing a prop on a component with
hydrate-never will cause it to hydrate)hydrate-on-visible
Hydrates the component when it becomes visible in the viewport.
app/pages/index.vue
Under the hood, this uses Vue’s built-in
hydrateOnVisible strategy.hydrate-on-idle
Hydrates the component when the browser is idle. This is suitable if you need the component to load as soon as possible, but not block the critical rendering path.
app/pages/index.vue
hydrate-on-interaction
Hydrates the component after a specified interaction (e.g., click, mouseover).
app/pages/index.vue
pointerenter, click and focus.
Client Components
If a component is meant to be rendered only client-side, you can add the.client suffix to your component.
app/pages/example.vue
This feature only works with Nuxt auto-imports and
#components imports. Explicitly importing these components from their real paths does not convert them into client-only components..client components are rendered only after being mounted. To access the rendered template using onMounted(), add await nextTick() in the callback of the onMounted() hook.Server Components
Server components allow server-rendering individual components within your client-side apps. It’s possible to use server components within Nuxt, even if you are generating a static site. That makes it possible to build complex sites that mix dynamic components, server-rendered HTML and even static chunks of markup. Server components can either be used on their own or paired with a client component.Standalone server components
Standalone server components will always be rendered on the server, also known as Islands components. When their props update, this will result in a network request that will update the rendered HTML in-place. Server components are currently experimental and in order to use them, you need to enable the ‘component islands’ feature in your nuxt.config:nuxt.config.ts
.server suffix and use them anywhere in your application automatically.
app/pages/example.vue
Paired with a Client component
In this case, the.server + .client components are two ‘halves’ of a component and can be used in advanced use cases for separate implementations of a component on server and client side.
app/pages/example.vue
Custom Directories
By default, only the~/components directory is scanned. If you want to add other directories, or change how the components are scanned within a subfolder of this directory, you can add additional directories to the configuration:
nuxt.config.ts