์์ฑ: 2026-03-04 05:39:06์์ : 2026-03-04 05:39:06
Nuxt ๋์๋ณด๋ ํ๋ก์ ํธ ์๋ฆฌ์ฆ (4): ๋์๋ณด๋ ๋ ์ด์์ ๊ตฌํ
์ด์ ๋์์ธ ์์คํ ๊ณผ ์ํ ๊ด๋ฆฌ๊ฐ ์ค๋น๋์์ผ๋, ๋ณธ๊ฒฉ์ ์ผ๋ก ๋์๋ณด๋์ ๋ผ๋์ธ **๋ ์ด์์(Layout)**์ ๋ง๋ค์ด ๋ณด๊ฒ ์ต๋๋ค. Naive UI์ ๋ ์ด์์ ์ปดํฌ๋ํธ๋ฅผ ํ์ฉํฉ๋๋ค.
1. ๊ธฐ๋ณธ ๋ ์ด์์ ๊ตฌ์กฐ (layouts/default.vue)
์ฌ์ด๋๋ฐ, ํค๋, ์ฝํ ์ธ ์์ญ์ผ๋ก ๋๋ ํ์ค ๋์๋ณด๋ ๊ตฌ์กฐ์ ๋๋ค.
<template>
<n-layout has-sider h-screen>
<!-- ์ฌ์ด๋๋ฐ -->
<n-layout-sider
bordered
collapse-mode="width"
:collapsed-width="64"
:width="240"
:collapsed="appStore.isSidebarCollapsed"
show-trigger
@collapse="appStore.toggleSidebar"
@expand="appStore.toggleSidebar"
>
<div class="h-16 flex-center font-bold text-lg overflow-hidden whitespace-nowrap">
{{ appStore.isSidebarCollapsed ? 'D' : 'Dashboard' }}
</div>
<n-menu :options="menuOptions" />
</n-layout-sider>
<n-layout>
<!-- ํค๋ -->
<n-layout-header bordered class="h-16 flex items-center justify-between px-6">
<div class="i-carbon-menu text-xl cursor-pointer" @click="appStore.toggleSidebar" />
<div class="flex items-center gap-4">
<span>{{ authStore.user.name }}</span>
<n-avatar round :src="authStore.user.avatar" />
</div>
</n-layout-header>
<!-- ์ฝํ
์ธ ์์ญ -->
<n-layout-content content-style="padding: 24px;" class="bg-gray-50/50">
<slot />
</n-layout-content>
</n-layout>
</n-layout>
</template>
<script setup>
import { useAppStore } from '@/stores/app'
import { useAuthStore } from '@/stores/auth'
const appStore = useAppStore()
const authStore = useAuthStore()
const menuOptions = [
{ label: 'ํ', key: 'home', icon: () => h('div', { class: 'i-carbon-home' }) },
{ label: 'ํต๊ณ', key: 'stats', icon: () => h('div', { class: 'i-carbon-chart-line' }) },
{ label: '์ค์ ', key: 'settings', icon: () => h('div', { class: 'i-carbon-settings' }) },
]
</script>2. ๋ ์ด์์์ ํต์ฌ ํฌ์ธํธ
has-sider:n-layout์์ ์ฌ์ด๋๋ฐ๊ฐ ํฌํจ๋ ๋ ๋ฐ๋์ ์ถ๊ฐํด์ผ ํ๋ ์์ฑ์ ๋๋ค.slot: ๊ฐ ํ์ด์ง์ ๋ด์ฉ์ด ๋ค์ด๊ฐ ์๋ฆฌ์ ๋๋ค.- ๋ฐ์ํ ๋์: ์ฌ์ด๋๋ฐ ์ ํ ์ํ๋ฅผ Pinia์ ์ฐ๋ํ์ฌ ํค๋์ ๋ฒํผ์ด๋ ์ฌ์ด๋๋ฐ ์์ฒด ํธ๋ฆฌ๊ฑฐ๋ก ์ ์ดํ ์ ์์ต๋๋ค.
3. UnoCSS๋ก ์ฌ๋ฐฑ๊ณผ ๋ฐฐ๊ฒฝ ์ฒ๋ฆฌ
content-style ์ธ์๋ UnoCSS๋ฅผ ์ฌ์ฉํ์ฌ ๋ํ
์ผํ ์คํ์ผ์ ์ก์ต๋๋ค.
h-screen: ์ ์ฒด ํ๋ฉด ๋์ด ์ฐจ์ง.bg-gray-50/50: ์ฝํ ์ธ ์์ญ์ ์ด์ง ํ์๋น ๋ฐฐ๊ฒฝ์ ์ฃผ์ด ์นด๋๊ฐ ๋๋ณด์ด๊ฒ ํจ.
4. ๊ฒฐ๋ก
๊น๋ํ๊ณ ์ ๋ฌธ์ ์ธ ๋์๋ณด๋ ๋ ์ด์์์ด ์์ฑ๋์์ต๋๋ค! ์ด์ ๋ง์ง๋ง ๋จ๊ณ๋ก ๋์๋ณด๋ ๋ฉ์ธ ํ์ด์ง์ ์ฐจํธ์ ๋ฐ์ดํฐ ํ๋ฅผ ์ฑ์ ๋ฃ์ด ๋ณด๊ฒ ์ต๋๋ค.