본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

페이지

원문 보기 위키 갱신

페이지 (Page)

Page는 페이지에 왼쪽/오른쪽 컬럼을 만들 수 있는 그리드 레이아웃 컴포넌트예요. 문서 사이트처럼 콘텐츠 중심의 페이지를 만드는 데 딱 맞아요.

출처: Nuxt UI

본문

사용법 (Usage)

Page 컴포넌트는 선택적인 왼쪽/오른쪽 컬럼으로 레이아웃을 만들 수 있게 도와줘요. 문서 사이트나 콘텐츠 중심의 페이지를 만드는 데 제격이에요.

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

    <template #right />
  </UPage>
</template>

[!TIP]

아무 slot도 지정하지 않으면 페이지는 중앙에 하나의 컬럼으로 표시돼요.

예시 (Examples)

[!NOTE]

이 예시들은 Nuxt Content를 사용하지만, 컴포넌트 자체는 어떤 콘텐츠 관리 시스템과도 함께 사용할 수 있어요.

레이아웃 안에서

레이아웃에서 Page 컴포넌트의 left slot으로 내비게이션을 표시할 수 있어요.

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

[!NOTE]

이 예시에서는 app.vue에서 주입한 내비게이션을 표시하기 위해 ContentNavigation 컴포넌트를 사용해요.

페이지 안에서

페이지에서 Page 컴포넌트의 right slot으로 목차를 표시할 수 있어요.

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

[!NOTE]

이 예시에서는 목차를 표시하기 위해 ContentToc 컴포넌트를 사용해요.

API

Props

/**
 * Props for the Page component
 */
interface PageProps {
  /**
   * The element or component this component should render as.
   * @default 'div'
   */
  as?: any;
  ui?: { root?: SlotClass; left?: SlotClass; center?: SlotClass; right?: SlotClass; } | undefined;
}

Slots

/**
 * Slots for the Page component
 */
interface PageSlots {
  left(): any;
  default(): any;
  right(): any;
}

테마 (Theme)

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'
          }
        }
      ]
    }
  }
})

더 알아보기 (Learn more)