Page

左右の列を持つページのグリッドレイアウト。

使用法

ページコンポーネントは、オプションの左右列を持つレイアウトを作成するのに役立ちます。ドキュメントサイトやその他のコンテンツ重視のページを作成するのに最適です。

<template>
  <UPage>
    <template #left />

    <template #right />
  </UPage>
</template>
スロットが指定されていない場合、ページは中央の単列レイアウトとして表示されます。

サンプル

これらの例はNuxt Contentを使用していますが、コンポーネントは任意のコンテンツ管理システムと統合できます。

レイアウト内

ナビゲーションを表示するには、leftスロットを持つレイアウトでPageコンポーネントを使用します。

layouts/docs.vue
<script setup lang="ts">
import type { ContentNavigationItem } from '@nuxt/content'

const navigation = inject<Ref<ContentNavigationItem[]>>('navigation')
</script>

<template>
  <UPage>
    <template #left>
      <UPageAside>
        <UContentNavigation :navigation="navigation" />
      </UPageAside>
    </template>

    <slot />
  </UPage>
</template>
この例では、ContentNavigationコンポーネントを使用して、app.vueに注入されたナビゲーションを表示します。

ページ内

rightスロットを持つページでPageコンポーネントを使用して、目次を表示します。

pages/[...slug].vue
<script setup lang="ts">
const route = useRoute()

definePageMeta({
  layout: 'docs'
})

const { data: page } = await useAsyncData(route.path, () => {
  return queryCollection('docs').path(route.path).first()
})

const { data: surround } = await useAsyncData(`${route.path}-surround`, () => {
  return queryCollectionItemSurroundings('content', route.path)
})
</script>

<template>
  <UPage>
    <UPageHeader :title="page.title" :description="page.description" />

    <UPageBody>
      <ContentRenderer :value="page" />

      <USeparator />

      <UContentSurround :surround="surround" />
    </UPageBody>

    <template #right>
      <UContentToc :links="page.body.toc.links" />
    </template>
  </UPage>
</template>
この例では、ContentTocコンポーネントを使用して目次を表示しています。

API

Props

Prop Default Type
as
'div'
any

The element or component this component should render as.

ui
{ root?: SlotClass; left?: SlotClass; center?: SlotClass; right?: SlotClass; }

スロット

Slot Type
left
{}
default
{}
right
{}

Theme

app.config.ts
export default defineAppConfig({
  ui: {
    page: {
      slots: {
        root: 'flex flex-col lg:grid lg:grid-cols-10 lg:gap-10',
        left: 'lg:col-span-2',
        center: 'lg:col-span-8',
        right: 'lg:col-span-2 order-first lg:order-last'
      },
      variants: {
        left: {
          true: ''
        },
        right: {
          true: ''
        }
      },
      compoundVariants: [
        {
          left: true,
          right: true,
          class: {
            center: 'lg:col-span-6'
          }
        },
        {
          left: false,
          right: false,
          class: {
            center: 'lg:col-span-10'
          }
        }
      ]
    }
  }
})
vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'

export default defineConfig({
  plugins: [
    vue(),
    ui({
      ui: {
        page: {
          slots: {
            root: 'flex flex-col lg:grid lg:grid-cols-10 lg:gap-10',
            left: 'lg:col-span-2',
            center: 'lg:col-span-8',
            right: 'lg:col-span-2 order-first lg:order-last'
          },
          variants: {
            left: {
              true: ''
            },
            right: {
              true: ''
            }
          },
          compoundVariants: [
            {
              left: true,
              right: true,
              class: {
                center: 'lg:col-span-6'
              }
            },
            {
              left: false,
              right: false,
              class: {
                center: 'lg:col-span-10'
              }
            }
          ]
        }
      }
    })
  ]
})

Changelog

No recent changes