Skip to content

Commit

Permalink
docs: add contents of the layout in examples (#26532)
Browse files Browse the repository at this point in the history
  • Loading branch information
xjccc committed Mar 28, 2024
1 parent 290dc27 commit 871404a
Showing 1 changed file with 39 additions and 3 deletions.
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"}

0 comments on commit 871404a

Please sign in to comment.