Vue Breadcrumb 컴포넌트
Breadcrumb은 페이지 계층 구조에 대한 맥락 정보를 보여 주는 컴포넌트예요. 지금 어디에 있는지 한눈에 알려 주고, 상위 페이지로 빠르게 돌아갈 수 있게 도와줘요.
출처: 문서
본문
Vue Breadcrumb Component
Breadcrumb provides contextual information about page hierarchy.
Import
import Breadcrumb from 'primevue/breadcrumb';
Accessibility
Screen Reader Breadcrumb은 nav 요소를 사용하고 어떤 속성이든 루트에 그대로 전달되기 때문에, aria-labelledby나 aria-label로 컴포넌트를 설명할 수 있어요. 내부에는 정렬된 리스트(ordered list)가 사용되고, 리스트 아이템 구분자에는 aria-hidden이 지정되어 스크린 리더가 무시하도록 되어 있어요. 마지막 링크가 현재 라우트를 나타낸다면 aria-current가 "page" 값을 갖고 추가돼요. Keyboard Support 특별한 키보드 상호작용은 필요 없고, 모든 menuitem은 페이지 탭 순서에 따라 포커스 가능해요.
Basic
Breadcrumb은 menuitem 컬렉션을 model로 필요로 하고, 루트 아이템은 home 프로퍼티로 정의해요.
<Breadcrumb :home="home" :model="items" />
Router
내비게이션이 있는 아이템은 router link 컴포넌트, 외부 링크, 프로그래매틱 내비게이션을 사용할 수 있도록 템플릿으로 정의해요.
<Breadcrumb :home="home" :model="items">
<template #item="{ item, props }">
<router-link v-if="item.route" v-slot="{ href, navigate }" :to="item.route" custom>
<a :href="href" v-bind="props.action" @click="navigate">
<span :class="[item.icon, 'text-color']" />
<span class="text-primary font-semibold">{{ item.label }}</span>
</a>
</router-link>
<a v-else :href="item.url" :target="item.target" v-bind="props.action">
<span class="text-surface-700 dark:text-surface-0">{{ item.label }}</span>
</a>
</template>
</Breadcrumb>
Composition API Example
<template>
<div class="card flex justify-center">
<Breadcrumb :home="home" :model="items">
<template #item="{ item, props }">
<router-link v-if="item.route" v-slot="{ href, navigate }" :to="item.route" custom>
<a :href="href" v-bind="props.action" @click="navigate">
<span :class="[item.icon, 'text-color']" />
<span class="text-primary font-semibold">{{ item.label }}</span>
</a>
</router-link>
<a v-else :href="item.url" :target="item.target" v-bind="props.action">
<span class="text-surface-700 dark:text-surface-0">{{ item.label }}</span>
</a>
</template>
</Breadcrumb>
</div>
</template>
<script setup>
import { ref } from "vue";
const home = ref({
icon: 'pi pi-home',
route: '/introduction'
});
const items = ref([
{ label: 'Components' },
{ label: 'Form' },
{ label: 'InputText', route: '/inputtext' }
]);
<\/script>
Template
item 템플릿을 사용하면 아이템 안에 커스텀 콘텐츠를 넣을 수 있어요. 아이템 사이의 구분자는 별도의 separator 템플릿을 가지고 있어요.
<Breadcrumb :home="home" :model="items">
<template #item="{ item }">
<a class="cursor-pointer" :href="item.url">
<span :class="item.icon"></span>
</a>
</template>
<template #separator> / </template>
</Breadcrumb>
Composition API Example
<template>
<div class="card flex justify-center">
<Breadcrumb :home="home" :model="items">
<template #item="{ item }">
<a class="cursor-pointer" :href="item.url">
<span :class="item.icon"></span>
</a>
</template>
<template #separator> / </template>
</Breadcrumb>
</div>
</template>
<script setup>
import { ref } from "vue";
const home = ref({ icon: 'pi pi-home' });
const items = ref([{ icon: 'pi pi-sitemap' }, { icon: 'pi pi-book' }, { icon: 'pi pi-wallet' }, { icon: 'pi pi-shopping-bag' }, { icon: 'pi pi-calculator' }]);
<\/script>