docs: add <script setup> usage for layouts (#1305)

This commit is contained in:
Aaron Ransley 2021-10-21 04:14:40 -06:00 committed by GitHub
parent 1a41c8819b
commit b91c8271e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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>
```