Skip to content

Container 布局容器

用于布局的容器组件,方便快速搭建页面的基本结构。采用 Flex 布局,包含 Container、Header、Aside、Main、Footer 五个子组件。

常见页面布局

Header + Main

Header
Main
Header + Main

Aside + Main

Main
Aside + Main

完整布局

Header + Aside + Main + Footer 的经典后台布局。Container 组件会自动检测子元素是否包含 Header 或 Footer,如果包含则自动切换为垂直方向布局。

Header
Main
Footer
完整布局

在 Nuxt 中使用

Container 组件完全支持 Nuxt 3/4 的 SSR 渲染。以下示例展示了在 Nuxt 的 layouts/default.vue 中搭建带侧边栏折叠的后台管理布局,内容区使用 <NuxtPage /> 渲染当前路由页面。

My App

当前路由内容(NuxtPage)
© 2024 YH-UI
Nuxt 中使用(layouts/default.vue)

SSR 注意事项

  • ✅ 所有 Props 和样式完全支持
  • ✅ Flex 布局方向自动检测正常工作
  • ✅ 插槽内容完整渲染
  • ✅ 结合 NuxtPage 页面容器使用
  • NuxtLink 路由链接完整支持
  • ✅ 支持响应式侧边栏折叠

SSR 安全性

Container 所有子组件均已通过 SSR 测试,确保服务端和客户端渲染完全一致,Hydration 无错误。

API

Container Props

属性名说明类型默认值
direction排列方向'horizontal' | 'vertical'自动检测(含 Header/Footer 时为 vertical)
themeOverrides主题覆盖变量ComponentThemeVars

Header Props

属性名说明类型默认值
height头部高度string'60px'
themeOverrides主题覆盖变量ComponentThemeVars

Aside Props

属性名说明类型默认值
width侧边栏宽度string'200px'
themeOverrides主题覆盖变量ComponentThemeVars

Main Props

属性名说明类型默认值
themeOverrides主题覆盖变量ComponentThemeVars
属性名说明类型默认值
height底部高度string'60px'
themeOverrides主题覆盖变量ComponentThemeVars

Slots

所有子组件均支持 default 默认插槽。

主题变量

Container 组件支持通过覆盖以下 CSS 变量来自定义局部样式:

变量名说明默认值
--yh-header-padding头部内边距0 20px
--yh-header-bg-color头部背景色transparent
--yh-header-border-bottom头部底部边框none
--yh-aside-bg-color侧边栏背景色transparent
--yh-aside-border-right侧边栏右侧边框none
--yh-main-padding主区域内边距20px
--yh-main-bg-color主区域背景色transparent
--yh-footer-padding底部内边距0 20px
--yh-footer-bg-color底部背景色transparent
--yh-footer-border-top底部顶部边框none

Released under the MIT License.