mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-18 17:35:57 +00:00
docs: add <script setup>
usage for layouts (#1305)
This commit is contained in:
parent
1a41c8819b
commit
b91c8271e4
@ -59,3 +59,45 @@ export default {
|
||||
};
|
||||
</script>
|
||||
```
|
||||
|
||||
### Example: using with `<script setup>`
|
||||
|
||||
If you are utilizing Vue `<script setup>` [compile-time syntactic sugar](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup), you can use a secondary `<script>` tag to set `layout` options as needed.
|
||||
|
||||
::alert{type=info}
|
||||
Learn more about [`<script setup>` and `<script>` tags co-existing](https://v3.vuejs.org/api/sfc-script-setup.html#usage-alongside-normal-script) in the Vue docs.
|
||||
::
|
||||
|
||||
Assuming this directory structure:
|
||||
|
||||
```bash
|
||||
-| layouts/
|
||||
---| custom.vue
|
||||
-| pages/
|
||||
---| my-page.vue
|
||||
```
|
||||
|
||||
And this `custom.vue` layout:
|
||||
|
||||
```vue
|
||||
<template>
|
||||
<div>
|
||||
Some shared layout content:
|
||||
<slot />
|
||||
</div>
|
||||
</template>
|
||||
```
|
||||
|
||||
You can set a page layout in `my-page.vue` — alongside the `<script setup>` tag — like this:
|
||||
|
||||
```vue
|
||||
<script>
|
||||
export default {
|
||||
layout: "custom",
|
||||
};
|
||||
</script>
|
||||
|
||||
<script setup>
|
||||
// your setup script
|
||||
</script>
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user