Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add contents of the layout in examples #26532

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 39 additions & 3 deletions docs/3.api/1.components/3.nuxt-layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ console.log(layoutCustomProps.title) // I am a custom layout

`<NuxtLayout />` renders incoming content via `<slot />`, which is then wrapped around Vue’s `<Transition />` component to activate layout transition. For this to work as expected, it is recommended that `<NuxtLayout />` is **not** the root element of the page component.

::code-group

```vue [pages/index.vue]
<template>
<div>
Expand All @@ -97,13 +99,27 @@ console.log(layoutCustomProps.title) // I am a custom layout
</template>
```

```vue [layouts/custom.vue]
<template>
<div>
<!-- named slot -->
<slot name="header" />
<slot />
</div>
</template>
```

::

:read-more{to="/docs/getting-started/transitions"}

## Layout's Ref

To get the ref of a layout component, access it through `ref.value.layoutRef`.

````vue [app.vue]
::code-group

```vue [app.vue]
<script setup lang="ts">
const layout = ref()

Expand All @@ -113,8 +129,28 @@ function logFoo () {
</script>

<template>
<NuxtLayout ref="layout" />
<NuxtLayout ref="layout">
default layout
</NuxtLayout>
</template>
````
```

```vue [layouts/default.vue]
<script setup lang="ts">
const foo = () => console.log('foo')
defineExpose({
foo
})
</script>

<template>
<div>
default layout
<slot />
</div>
</template>
```

::

:read-more{to="/docs/guide/directory-structure/layouts"}