You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/2.guide/2.directory-structure/1.components.md
+7-80Lines changed: 7 additions & 80 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -244,6 +244,10 @@ This feature only works with Nuxt auto-imports and `#components` imports. Explic
244
244
`.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.
You can also achieve a similar result with the `<ClientOnly>` component.
249
+
::
250
+
247
251
## Server Components
248
252
249
253
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.
@@ -357,89 +361,12 @@ In this case, the `.server` + `.client` components are two 'halves' of a compone
357
361
</template>
358
362
```
359
363
360
-
## `<ClientOnly>` Component
361
-
362
-
Nuxt provides the [`<ClientOnly>`](/docs/api/components/client-only) component for purposely rendering a component only on client side.
363
-
364
-
```vue [pages/example.vue]
365
-
<template>
366
-
<div>
367
-
<Sidebar />
368
-
<ClientOnly>
369
-
<!-- this component will only be rendered on client-side -->
370
-
<Comments />
371
-
</ClientOnly>
372
-
</div>
373
-
</template>
374
-
```
364
+
## Built-In Nuxt Components
375
365
376
-
Use a slot as fallback until `<ClientOnly>`is mounted on client side.
366
+
There are a number of components that Nuxt provides, including `<ClientOnly>`and `<DevOnly>`. You can read more about them in the API documentation.
377
367
378
-
```vue [pages/example.vue]
379
-
<template>
380
-
<div>
381
-
<Sidebar />
382
-
<!-- This renders the "span" element on the server side -->
383
-
<ClientOnly fallbackTag="span">
384
-
<!-- this component will only be rendered on client side -->
385
-
<Comments />
386
-
<template #fallback>
387
-
<!-- this will be rendered on server side -->
388
-
<p>Loading comments...</p>
389
-
</template>
390
-
</ClientOnly>
391
-
</div>
392
-
</template>
393
-
```
394
-
395
-
<!-- TODO: Add back after passing treeshakeClientOnly experiment -->
396
-
<!--
397
-
::note
398
-
Make sure not to _nest_ `<ClientOnly>` components or other client-only components. Nuxt performs an optimization to remove the contents of these components from the server-side render, which can break in this case.
368
+
::read-more{to="/docs/api"}
399
369
::
400
-
-->
401
-
402
-
## `<DevOnly>` Component
403
-
404
-
Nuxt provides the `<DevOnly>` component to render a component only during development.
405
-
406
-
The content will not be included in production builds and tree-shaken.
407
-
408
-
```vue [pages/example.vue]
409
-
<template>
410
-
<div>
411
-
<Sidebar />
412
-
<DevOnly>
413
-
<!-- this component will only be rendered during development -->
414
-
<LazyDebugBar />
415
-
416
-
<!-- if you ever require to have a replacement during production -->
417
-
<!-- be sure to test these using `nuxt preview` -->
418
-
<template #fallback>
419
-
<div><!-- empty div for flex.justify-between --></div>
420
-
</template>
421
-
</DevOnly>
422
-
</div>
423
-
</template>
424
-
```
425
-
426
-
## `<NuxtClientFallback>` Component
427
-
428
-
Nuxt provides the `<NuxtClientFallback>` component to render its content on the client if any of its children trigger an error in SSR.
429
-
You can specify a `fallbackTag` to make it render a specific tag if it fails to render on the server.
430
-
431
-
```vue [pages/example.vue]
432
-
<template>
433
-
<div>
434
-
<Sidebar />
435
-
<!-- this component will be rendered on client-side -->
Copy file name to clipboardExpand all lines: docs/3.api/1.components/1.client-only.md
+12-5Lines changed: 12 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,11 @@ links:
8
8
size: xs
9
9
---
10
10
11
-
The `<ClientOnly>` component renders its slot only in client-side. To import a component only on the client, register the component in a client-side only plugin.
11
+
The `<ClientOnly>` component is used for purposely rendering a component only on client side.
12
+
13
+
::note
14
+
The content of the default slot will be tree-shaken out of the server build. (This does mean that any CSS used by components within it may not be inlined when rendering the initial HTML.)
15
+
::
12
16
13
17
## Props
14
18
@@ -19,6 +23,7 @@ The `<ClientOnly>` component renders its slot only in client-side. To import a c
19
23
<template>
20
24
<div>
21
25
<Sidebar />
26
+
<!-- The <Comment> component will only be rendered on client-side -->
0 commit comments