|
| 1 | +--- |
| 2 | +title: Nuxt 3 Integration |
| 3 | +--- |
| 4 | + |
| 5 | +# {{$frontmatter.title}} |
| 6 | + |
| 7 | +The integration in Nuxt is done in a few steps. |
| 8 | + |
| 9 | +The following settings must be adjusted: |
| 10 | + |
| 11 | +- Layout |
| 12 | +- Page Component |
| 13 | + |
| 14 | +## Layout |
| 15 | + |
| 16 | +In the layout, the component `ContentContainer` must be placed around the respective page slot. |
| 17 | +The `ContentContainer` defined there represents the `main` of the page. |
| 18 | + |
| 19 | +::: code-group |
| 20 | + |
| 21 | +```vue [layouts/default.vue] |
| 22 | +<template> |
| 23 | + <div> |
| 24 | + <!-- main --> |
| 25 | + <ContentContainer> |
| 26 | + <slot /> |
| 27 | + </ContentContainer> |
| 28 | + </div> |
| 29 | +</template> |
| 30 | +
|
| 31 | +<script setup> |
| 32 | +import { ContentContainer } from 'vue-semantic-structure' |
| 33 | +</script> |
| 34 | +``` |
| 35 | + |
| 36 | +::: |
| 37 | + |
| 38 | +## Page Component |
| 39 | + |
| 40 | +With the exception of the first component, each additional component must contain a `ContentContainer`. |
| 41 | + |
| 42 | +::: code-group |
| 43 | + |
| 44 | +```vue[pages/index.vue] |
| 45 | +<template> |
| 46 | + <div> |
| 47 | + <FirstComponent /> |
| 48 | + <OtherComponentA /> |
| 49 | + <OtherComponentB /> |
| 50 | + </div> |
| 51 | +</template> |
| 52 | +
|
| 53 | +<script setup> |
| 54 | +import FirstComponent from '~/components/FirstComponent.vue' |
| 55 | +import OtherComponentA from '~/components/OtherComponentA.vue' |
| 56 | +import OtherComponentB from '~/components/OtherComponentB.vue' |
| 57 | +
|
| 58 | +``` |
| 59 | + |
| 60 | +```vue[FirstComponent.vue] |
| 61 | +<template> |
| 62 | + <header> |
| 63 | + <!-- h1 --> |
| 64 | + <ContentHeadline>Headline</ContentHeadline> |
| 65 | + </header> |
| 66 | +</template> |
| 67 | +
|
| 68 | +<script setup> |
| 69 | +import { ContentHeadline } from 'vue-semantic-structure' |
| 70 | +</script> |
| 71 | +``` |
| 72 | + |
| 73 | +```vue[OtherComponentA.vue] |
| 74 | +<template> |
| 75 | + <!-- article --> |
| 76 | + <ContentContainer> |
| 77 | + <!-- h2 --> |
| 78 | + <ContentHeadline>Headline</ContentHeadline> |
| 79 | + </ContentContainer> |
| 80 | +</template> |
| 81 | +
|
| 82 | +<script setup> |
| 83 | +import { ContentContainer, ContentHeadline } from 'vue-semantic-structure' |
| 84 | +</script> |
| 85 | +``` |
| 86 | + |
| 87 | +```vue[OtherComponentB.vue] |
| 88 | +<template> |
| 89 | + <!-- article --> |
| 90 | + <ContentContainer> |
| 91 | + <!-- h2 --> |
| 92 | + <ContentHeadline>Headline</ContentHeadline> |
| 93 | + </ContentContainer> |
| 94 | +</template> |
| 95 | +
|
| 96 | +<script setup> |
| 97 | +import { ContentContainer, ContentHeadline } from 'vue-semantic-structure' |
| 98 | +</script> |
| 99 | +``` |
| 100 | + |
| 101 | +::: |
| 102 | + |
| 103 | +## Register Global |
| 104 | + |
| 105 | +`ContentHeadline` and `ContentContainer` can also be defined globally. |
| 106 | + |
| 107 | +Only one plugin needs to be created for this. |
| 108 | + |
| 109 | +::: code-group |
| 110 | + |
| 111 | +```js[Nuxt 3: plugin/vue-semantic-structure.js] |
| 112 | +import { defineNuxtPlugin } from 'nuxt/app'; |
| 113 | +import { ContentHeadline, ContentContainer } from 'vue-semantic-structure'; |
| 114 | +
|
| 115 | +export default defineNuxtPlugin({ |
| 116 | + async setup(nuxtApp) { |
| 117 | + nuxtApp.vueApp.component('ContentHeadline', ContentHeadline); |
| 118 | + nuxtApp.vueApp.component('ContentContainer', ContentContainer); |
| 119 | + } |
| 120 | +}); |
| 121 | +``` |
| 122 | + |
| 123 | +::: |
0 commit comments