Skip to content

Navbar 导航栏

导航栏组件用于在页面顶部展示品牌标识、主导航菜单和工具栏操作入口。

TIP

⚠️ 受限于 whyframe 和 vitepress 的演示框架,下方交互演示可能呈现移动端自适应效果(汉堡按钮可见)。请点击顶部导航栏的「演示」链接查看完整的桌面端效果。

基本用法

通过 variant 控制背景色变体,theme 控制深色/浅色主题。

vue
<TNavbar variant="transparent">
  <template #brand>
    <TNavbarBrand href="#">My App</TNavbarBrand>
  </template>
  <TNavMenu :items="menuItems" />
  <template #actions>
    <a class="nav-link px-0" href="#"><IconMoon class="icon icon-1" /></a>
  </template>
</TNavbar>

深色主题

设置 theme="dark" 启用深色模式。

vue
<TNavbar theme="dark">
  <template #brand>
    <TNavbarBrand href="#">Dashboard</TNavbarBrand>
  </template>
  <TNavMenu :items="menuItems" />
</TNavbar>

主题色

使用 variant="primary" 配合深色主题。

vue
<TNavbar variant="primary" theme="dark">
  ...
</TNavbar>

数据驱动菜单

通过 items 传入菜单配置数组,自动渲染导航链接和下拉菜单。

vue
<TNavMenu :items="[
  { label: '首页', icon: IconStar, href: '#', active: true },
  { label: '项目', href: '#', badge: '3' },
  { label: '更多', children: [
    { label: '子项', href: '#' },
  ]},
]" />

多层菜单与激活高亮

支持无限级嵌套子菜单,深层 active 状态会递归高亮所有父级项。下例中"所有文章"处于激活态,其父级"内容管理"→"文章管理"均自动高亮。

vue
<TNavMenu :items="[
  { label: '仪表盘', icon: IconStar, href: '#', active: true },
  { label: '内容管理', icon: IconStar, children: [
    { label: '文章管理', children: [
      { label: '所有文章', href: '#', active: true },
      { label: '分类管理', href: '#' },
    ]},
    { label: '页面管理', href: '#' },
  ]},
]" />

API

TNavbar Props

Prop说明类型默认值
variant背景色变体'light' | 'dark' | 'transparent' | 'primary''light'
sticky是否吸顶booleanfalse
theme深色/浅色主题'light' | 'dark'
expand折叠断点'sm' | 'md' | 'lg' | 'xl''md'
noPrint是否不打印booleantrue

TNavbar Slots

插槽说明
brand品牌/Logo 区域
actions右侧工具栏
default主导航菜单区
toggler自定义移动端折叠按钮

TNavMenu Props

Prop说明类型默认值
items菜单配置NavMenuItem[][]
fill全宽填充booleanfalse
属性类型说明
labelstring显示文字
iconIcon图标组件
badgestring | { text, color }徽标
hrefstring链接地址
activeboolean是否激活
disabledboolean是否禁用
childrenNavMenuItem[]子菜单(自动下拉)

TNavbarBrand Props

Prop说明类型默认值
logoLogo 图片 URLstring
href跳转链接string'.'
logoWidth图片宽度number110
logoHeight图片高度number32