NavMenu 主导航
顶部水平导航栏,每一项可挂富面板(多列链接 + 描述),3 种 variant、hover / click 触发。
基础用法
items 是顶层菜单数组,每项要么是简单链接(href),要么有 links[] 子列表。后者会在 hover / click 时打开富面板,每条 link 可带 description 和 icon。columns 控制面板每行多少列(1 / 2 / 3)。
<script setup lang="ts">
import { ref } from 'vue';
import { CfNavMenu, type NavMenuItem } from '@chufix-design/vue';
const active = ref('products');
const items: NavMenuItem[] = [
{
key: 'products',
label: '产品',
columns: 2,
links: [
{ label: '组件库', description: 'Vue 3 与 React 双框架同源', href: '#' },
{ label: 'Tokens', description: 'OKLCH 设计变量与三套主题', href: '#' },
{ label: '图标', description: '16x16 sprite', href: '#' },
{ label: 'CLI', description: 'npx chufix add', href: '#' },
],
},
{ key: 'docs', label: '文档', links: [{ label: '快速开始', href: '#' }] },
{ key: 'pricing', label: '价格', href: '#' },
];
</script>
<template>
<CfNavMenu :items="items" :active="active" />
</template> import { CfNavMenu, type NavMenuItem } from '@chufix-design/react';
const items: NavMenuItem[] = [/* ... */];
<CfNavMenu items={items} active="products" /> 3 种 variant
underline—— 当前项底部细下划线(默认,最克制)pill—— 当前项变成填充胶囊minimal—— 仅文字颜色变化,无任何形状提示
variant = underline(默认)
variant = pill
variant = minimal
<CfNavMenu :items="items" :active="a" variant="underline" />
<CfNavMenu :items="items" :active="b" variant="pill" />
<CfNavMenu :items="items" :active="c" variant="minimal" /> <CfNavMenu items={items} active={a} variant="underline" />
<CfNavMenu items={items} active={b} variant="pill" />
<CfNavMenu items={items} active={c} variant="minimal" /> 触发方式
trigger —— hover(默认,鼠标悬停就打开)/ click(点击触发,更适合移动端或避免误触)。
trigger = hover(默认)
trigger = click
<CfNavMenu :items="items" :active="a" trigger="hover" />
<CfNavMenu :items="items" :active="b" trigger="click" /> <CfNavMenu items={items} active={a} trigger="hover" />
<CfNavMenu items={items} active={b} trigger="click" /> API
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
items | NavMenuItem[] | [] | 顶级菜单条目 |
active | string | — | 当前活动项的 key,影响下划线 / 高亮 |
variant | 'underline' | 'pill' | 'minimal' | 'underline' | 视觉模式 |
trigger | 'hover' | 'click' | 'hover' | 富面板的触发方式 |
类型导出:
interface NavMenuItem {
key: string;
label: string;
href?: string;
links?: NavMenuLink[];
columns?: 1 | 2 | 3;
disabled?: boolean;
}
interface NavMenuLink {
label: string;
description?: string;
href: string;
icon?: VNode | ReactNode;
}
事件:navigate(item)(React 端:onNavigate),仅在简单链接被点击(无 links 子项)时触发。
反馈与讨论
NavMenu 主导航 的讨论