Menu 選單
網站的導航選單,可以橫著放在頁頭,也可以豎著放在側邊欄,支援多級子選單和折疊。由 HuiMenu、HuiSubMenu、HuiMenuItem 三個元件配合使用。
引入
import { HuiMenu, HuiSubMenu, HuiMenuItem } from '@nscode/handy-ui'
基礎用法
預設是縱向選單。每個 HuiMenuItem 和 HuiSubMenu 都要有一個唯一的 index。default-active 指定一開始選中哪一項,點選單項時觸發 select,參數裡有這一項的 index 和它所在的各級子選單的 index。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiMenu, HuiSubMenu, HuiMenuItem } from '@nscode/handy-ui'
const selected = ref('1')
const path = ref<string[]>([])
const handleSelect = (index: string, indexPath: string[]) => {
selected.value = index
path.value = indexPath
}
</script>
<template>
<HuiMenu default-active="1" style="width: 240px" @select="handleSelect">
<HuiMenuItem index="1">工作臺</HuiMenuItem>
<HuiSubMenu index="2" title="系統管理">
<HuiMenuItem index="2-1">使用者管理</HuiMenuItem>
<HuiMenuItem index="2-2">角色管理</HuiMenuItem>
</HuiSubMenu>
<HuiMenuItem index="3">消息中心</HuiMenuItem>
</HuiMenu>
<p style="margin-top: 12px">
選中:{{ selected }},所在子選單:{{ path.length ? path.join(' / ') : '無' }}
</p>
</template>
選單方向
mode 可選 vertical(縱向,預設)和 horizontal(橫向)。
- 縱向選單豎著排,子選單就地展開在標題下面,適合放在側邊欄。
- 橫向選單橫著排,高 60px,適合放在頁頭。子選單在標題下方以浮層彈出,滑鼠移入 150 毫秒後打開,移出 150 毫秒後收起;多級子選單在上一級浮層的右側彈出。點了某個選單項後,浮層全部收起。選單項放不下時,選單可以橫向捲動,子選單標題不會被壓縮。
<template>
<HuiSpace direction="vertical" fill size="large">
<div>
<p class="row-label">horizontal</p>
<HuiMenu mode="horizontal" default-active="1">
<HuiMenuItem index="1">首頁</HuiMenuItem>
<HuiSubMenu index="2" title="產品中心">
<HuiMenuItem index="2-1">產品清單</HuiMenuItem>
<HuiMenuItem index="2-2">產品分類</HuiMenuItem>
<HuiSubMenu index="2-3" title="更多">
<HuiMenuItem index="2-3-1">產品統計</HuiMenuItem>
<HuiMenuItem index="2-3-2">產品記錄</HuiMenuItem>
</HuiSubMenu>
</HuiSubMenu>
<HuiMenuItem index="3">關于我們</HuiMenuItem>
</HuiMenu>
</div>
<div>
<p class="row-label">vertical</p>
<HuiMenu mode="vertical" default-active="1" style="width: 240px">
<HuiMenuItem index="1">首頁</HuiMenuItem>
<HuiSubMenu index="2" title="產品中心">
<HuiMenuItem index="2-1">產品清單</HuiMenuItem>
<HuiMenuItem index="2-2">產品分類</HuiMenuItem>
<HuiSubMenu index="2-3" title="更多">
<HuiMenuItem index="2-3-1">產品統計</HuiMenuItem>
<HuiMenuItem index="2-3-2">產品記錄</HuiMenuItem>
</HuiSubMenu>
</HuiSubMenu>
<HuiMenuItem index="3">關于我們</HuiMenuItem>
</HuiMenu>
</div>
</HuiSpace>
</template>
<style scoped>
.row-label {
margin: 0 0 8px;
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
</style>
橫向選單也可以帶圖示、禁用項:
<template>
<HuiMenu mode="horizontal" default-active="1">
<HuiMenuItem index="1" icon="home">首頁</HuiMenuItem>
<HuiSubMenu index="2" title="產品中心" icon="apps">
<HuiMenuItem index="2-1" icon="file">產品清單</HuiMenuItem>
<HuiMenuItem index="2-2" icon="folder">產品分類</HuiMenuItem>
</HuiSubMenu>
<HuiMenuItem index="3" icon="bell">消息</HuiMenuItem>
<HuiMenuItem index="4" icon="lock" disabled>管理後臺</HuiMenuItem>
</HuiMenu>
</template>
多級子選單
縱向選單裡,子選單就地展開在標題下面,點標題展開或收起,子級按層級縮進。選中某個子選單裡的項時,它所在的各級子選單標題也會顯示成作用中色。
<template>
<HuiMenu default-active="2-2-1" style="width: 240px">
<HuiMenuItem index="1">工作臺</HuiMenuItem>
<HuiSubMenu index="2" title="系統管理">
<HuiMenuItem index="2-1">使用者管理</HuiMenuItem>
<HuiSubMenu index="2-2" title="權限管理">
<HuiMenuItem index="2-2-1">角色管理</HuiMenuItem>
<HuiMenuItem index="2-2-2">選單管理</HuiMenuItem>
</HuiSubMenu>
</HuiSubMenu>
</HuiMenu>
</template>
預設展開和預設作用中項目
default-active 指向某個子選單裡的項時,掛載後會自動展開它所在的各級子選單(只在縱向、沒有折疊時這樣做)。default-openeds 指定一開始展開哪些子選單。
這兩個屬性執行時修改也會生效:改 default-active 會選中新的項並展開它所在的子選單;default-openeds 的內容變了,展開的子選單會重置成新的清單。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiMenu, HuiSubMenu, HuiMenuItem, HuiButton, HuiSpace } from '@nscode/handy-ui'
const active = ref('2-1')
const openeds = ref(['3'])
</script>
<template>
<HuiSpace wrap style="margin-bottom: 12px">
<HuiButton @click="active = '3-2'">選中“操作記錄”</HuiButton>
<HuiButton @click="active = '2-2'">選中“角色管理”</HuiButton>
<HuiButton @click="openeds = ['2', '3']">展開全部</HuiButton>
<HuiButton @click="openeds = []">收起全部</HuiButton>
</HuiSpace>
<HuiMenu :default-active="active" :default-openeds="openeds" style="width: 240px">
<HuiMenuItem index="1">工作臺</HuiMenuItem>
<HuiSubMenu index="2" title="系統管理">
<HuiMenuItem index="2-1">使用者管理</HuiMenuItem>
<HuiMenuItem index="2-2">角色管理</HuiMenuItem>
</HuiSubMenu>
<HuiSubMenu index="3" title="記錄">
<HuiMenuItem index="3-1">登入記錄</HuiMenuItem>
<HuiMenuItem index="3-2">操作記錄</HuiMenuItem>
</HuiSubMenu>
</HuiMenu>
</template>
只展開一個子選單(手風琴)
unique-opened 為 true 時,展開一個子選單會自動收起其他不相關的子選單,它自己的上級不受影響。下面左邊是預設,可以同時展開多個;右邊開了 unique-opened:
<template>
<HuiSpace align="start" size="large" wrap>
<HuiMenu style="width: 240px">
<HuiSubMenu index="1" title="系統管理">
<HuiMenuItem index="1-1">使用者管理</HuiMenuItem>
<HuiMenuItem index="1-2">角色管理</HuiMenuItem>
</HuiSubMenu>
<HuiSubMenu index="2" title="記錄">
<HuiMenuItem index="2-1">登入記錄</HuiMenuItem>
<HuiMenuItem index="2-2">操作記錄</HuiMenuItem>
</HuiSubMenu>
</HuiMenu>
<HuiMenu unique-opened style="width: 240px">
<HuiSubMenu index="1" title="系統管理">
<HuiMenuItem index="1-1">使用者管理</HuiMenuItem>
<HuiMenuItem index="1-2">角色管理</HuiMenuItem>
</HuiSubMenu>
<HuiSubMenu index="2" title="記錄">
<HuiMenuItem index="2-1">登入記錄</HuiMenuItem>
<HuiSubMenu index="2-2" title="操作記錄">
<HuiMenuItem index="2-2-1">新增記錄</HuiMenuItem>
<HuiMenuItem index="2-2-2">刪除記錄</HuiMenuItem>
</HuiSubMenu>
</HuiSubMenu>
</HuiMenu>
</HuiSpace>
</template>
圖示和折疊
HuiMenuItem 和 HuiSubMenu 的 icon 在文字前面顯示一個圖示(HuiIcon 的 name)。collapse 為 true 時選單寬度變成 64px,頂層的選單項和子選單標題只顯示圖示;子選單改成在右側以浮層彈出,懸停或點擊標題打開。切到折疊時,已經展開的子選單會全部收起。
折疊模式下頂層項要寫 icon,否則只剩一塊空白。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiMenu, HuiSubMenu, HuiMenuItem, HuiSwitch } from '@nscode/handy-ui'
const collapsed = ref(false)
</script>
<template>
<div style="margin-bottom: 12px">
<HuiSwitch v-model="collapsed" active-text="折疊" />
</div>
<HuiMenu :collapse="collapsed" default-active="1">
<HuiMenuItem index="1" icon="home">工作臺</HuiMenuItem>
<HuiSubMenu index="2" title="系統管理" icon="setting">
<HuiMenuItem index="2-1" icon="user">使用者管理</HuiMenuItem>
<HuiMenuItem index="2-2" icon="users">角色管理</HuiMenuItem>
</HuiSubMenu>
<HuiMenuItem index="3" icon="bell">消息中心</HuiMenuItem>
</HuiMenu>
</template>
禁用
HuiMenuItem 或 HuiSubMenu 的 disabled 為 true 時,點擊、懸停和鍵盤都不起作用,Tab 鍵也會跳過它。子選單裡的項也可以單獨禁用。
<template>
<HuiMenu style="width: 240px" :default-openeds="['4']">
<HuiMenuItem index="1">工作臺</HuiMenuItem>
<HuiMenuItem index="2" disabled>資料大屏(建設中)</HuiMenuItem>
<HuiSubMenu index="3" title="系統管理" disabled>
<HuiMenuItem index="3-1">使用者管理</HuiMenuItem>
</HuiSubMenu>
<HuiSubMenu index="4" title="記錄">
<HuiMenuItem index="4-1">登入記錄</HuiMenuItem>
<HuiMenuItem index="4-2" disabled>審計記錄(無權限)</HuiMenuItem>
</HuiSubMenu>
</HuiMenu>
</template>
自訂顏色
background-color、text-color、active-text-color 分別設定選單的背景色、文字色和選取項的文字色,橫向、折疊模式下的浮層也用同樣的顏色。值會寫進行內樣式,可以用主題變數。
<template>
<HuiSpace direction="vertical" fill>
<HuiMenu
mode="horizontal"
default-active="1"
background-color="var(--hui-color-primary-darker)"
text-color="var(--hui-color-white)"
active-text-color="var(--hui-color-warning)"
>
<HuiMenuItem index="1" icon="home">工作臺</HuiMenuItem>
<HuiSubMenu index="2" title="系統管理" icon="setting">
<HuiMenuItem index="2-1">使用者管理</HuiMenuItem>
<HuiMenuItem index="2-2">角色管理</HuiMenuItem>
</HuiSubMenu>
<HuiMenuItem index="3" icon="bell">消息中心</HuiMenuItem>
</HuiMenu>
<HuiMenu
default-active="1"
background-color="var(--hui-color-primary-darker)"
text-color="var(--hui-color-white)"
active-text-color="var(--hui-color-warning)"
style="width: 240px"
>
<HuiMenuItem index="1" icon="home">工作臺</HuiMenuItem>
<HuiSubMenu index="2" title="系統管理" icon="setting">
<HuiMenuItem index="2-1">使用者管理</HuiMenuItem>
<HuiMenuItem index="2-2">角色管理</HuiMenuItem>
</HuiSubMenu>
</HuiMenu>
</HuiSpace>
</template>
自訂標題
HuiMenuItem 的文字可以寫在預設插槽裡,也可以寫在 title 插槽裡,兩個都寫時只顯示 title 插槽。折疊模式下頂層項隱藏的就是這部分內容,圖示仍然顯示。
HuiSubMenu 的 title 插槽替換掉圖示和標題文字(右邊的箭頭保留)。標題行是兩端對齊的,插槽裡有多個元素時用一個元素包起來,否則它們會被拉開。折疊模式下元件分不清插槽裡哪部分是圖示、哪部分是文字,不會隱藏它,所以要折疊的選單請用 icon 和 title 屬性。
<script setup lang="ts">
import { HuiMenu, HuiSubMenu, HuiMenuItem, HuiIcon } from '@nscode/handy-ui'
</script>
<template>
<HuiMenu style="width: 240px">
<HuiMenuItem index="1">
<template #title>工作臺</template>
</HuiMenuItem>
<HuiSubMenu index="2">
<template #title>
<span>
<HuiIcon name="mail" />
消息中心
<span style="color: var(--hui-text-color-secondary)">(12 條未讀)</span>
</span>
</template>
<HuiMenuItem index="2-1">站內信</HuiMenuItem>
<HuiMenuItem index="2-2">系統通知</HuiMenuItem>
</HuiSubMenu>
</HuiMenu>
</template>
路由模式
router 為 true 時,點擊選單項先觸發 select,再呼叫 app.config.globalProperties.$router.push(route ?? index)。route 可以是路徑字串或路由物件;沒傳時使用 index 作為目標。
導航等待期間保留原醒目狀態,成功後按實際落地的完整路由(包含查詢參數)匹配選單。重新導向後醒目標示對應選單,沒有匹配項則清除醒目狀態;多個選單指向相同目標時優先本次點擊項。守衛取消、重複導航或導航異常不改變醒目狀態,異常在元件內處理並輸出 [HandyUI] 診斷。較早導航、卸載前的導航,以及業務在等待中顯式修改 default-active 前的導航,都不會覆蓋後續醒目狀態。
select 是即時點擊通知,不代表導航成功。透過瀏覽器前進、後退或業務程式碼跳轉時,仍需把業務計算的作用中項目綁定到 default-active,選單不會主動監聽所有路由變化。元件使用應用 app.use(router) 後提供的 $router;沒有註冊路由時按普通選單同步選擇。
<script setup lang="ts">
import { useRoute } from 'vue-router'
import { HuiMenu, HuiMenuItem } from '@nscode/handy-ui'
const route = useRoute()
</script>
<template>
<HuiMenu router :default-active="route.path" style="width: 240px">
<HuiMenuItem index="/dashboard" route="/dashboard">工作臺</HuiMenuItem>
<HuiMenuItem index="/users" :route="{ path: '/users', query: { page: 1 } }"
>使用者管理</HuiMenuItem
>
</HuiMenu>
</template>
浮層的自訂類名
HuiSubMenu 的 popper-class 會加到子選單的清單 ul(類名 hui-sub-menu__menu)上。橫向、折疊模式下這個清單是浮層,掛在 body 下,所以:
- 樣式不要寫在
scoped裡,要寫成全域樣式; - 不要用
.hui-menu .my-popup這類以選單為祖先的後代選擇器,直接用.my-popup。
<template>
<HuiMenu mode="horizontal">
<HuiSubMenu index="1" title="更多" popper-class="my-menu-popup">
<HuiMenuItem index="1-1">幫助文件</HuiMenuItem>
<HuiMenuItem index="1-2">意見回饋</HuiMenuItem>
</HuiSubMenu>
</HuiMenu>
</template>
<style>
.my-menu-popup {
min-width: 260px;
border: 1px solid var(--hui-border-color);
}
</style>
監聽展開和收起
子選單展開時觸發 open,收起時觸發 close,參數是這個子選單的 index 和它的各級上級子選單的 index。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiMenu, HuiSubMenu, HuiMenuItem } from '@nscode/handy-ui'
const log = ref('還沒有展開或收起')
const handleOpen = (index: string, indexPath: string[]) => {
log.value = `open:${index},上級:${indexPath.length ? indexPath.join(' / ') : '無'}`
}
const handleClose = (index: string, indexPath: string[]) => {
log.value = `close:${index},上級:${indexPath.length ? indexPath.join(' / ') : '無'}`
}
</script>
<template>
<HuiMenu style="width: 240px" @open="handleOpen" @close="handleClose">
<HuiSubMenu index="1" title="系統管理">
<HuiMenuItem index="1-1">使用者管理</HuiMenuItem>
<HuiSubMenu index="1-2" title="權限管理">
<HuiMenuItem index="1-2-1">角色管理</HuiMenuItem>
<HuiMenuItem index="1-2-2">選單管理</HuiMenuItem>
</HuiSubMenu>
</HuiSubMenu>
<HuiSubMenu index="2" title="記錄">
<HuiMenuItem index="2-1">登入記錄</HuiMenuItem>
</HuiSubMenu>
</HuiMenu>
<p style="margin-top: 12px">{{ log }}</p>
</template>
通過方法展開、收起
透過 HuiMenu 的 ref 呼叫 open(index, indexPath)、close(index, indexPath)。indexPath 是這個子選單的各級上級子選單的 index,頂層子選單傳 [];unique-opened 時靠它判斷哪些子選單要保留。ref 上還能讀到目前選取項 activeIndex 和展開的子選單 openedMenus。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiMenu, HuiSubMenu, HuiMenuItem, HuiButton, HuiSpace } from '@nscode/handy-ui'
const menuRef = ref<InstanceType<typeof HuiMenu>>()
const state = ref('')
const readState = () => {
const menu = menuRef.value
if (!menu) return
const opened = Array.from(menu.openedMenus)
state.value = `activeIndex:${menu.activeIndex || '無'},openedMenus:${opened.length ? opened.join('、') : '無'}`
}
</script>
<template>
<div style="margin-bottom: 12px">
<HuiSpace wrap>
<HuiButton @click="menuRef?.open('2', [])">展開系統管理</HuiButton>
<HuiButton @click="menuRef?.close('2', [])">收起系統管理</HuiButton>
<HuiButton @click="readState">讀取狀態</HuiButton>
<span>{{ state }}</span>
</HuiSpace>
</div>
<HuiMenu ref="menuRef" default-active="1" style="width: 240px">
<HuiMenuItem index="1">工作臺</HuiMenuItem>
<HuiSubMenu index="2" title="系統管理">
<HuiMenuItem index="2-1">使用者管理</HuiMenuItem>
<HuiMenuItem index="2-2">角色管理</HuiMenuItem>
</HuiSubMenu>
</HuiMenu>
</template>
鍵盤操作
選單使用一個Tab停留點。進入後用方向鍵導航,縱向展開時包含已經展開的各級內嵌項;每層浮層獨立導航。禁用項和隱藏分支不參與,父元件重新呈現不會主動搶走外部焦點。輸入法組合、229和Ctrl/Meta/Alt組合鍵留給輸入或系統。
| 按鍵 | 作用 |
|---|---|
↑、↓ | 縱向展開時按可見DOM順序循環穿過內嵌子項;浮層裡只在目前層循環 |
←、→ | 橫向選單的頂層:在頂層各項之間循環移動焦點 |
Enter、空白 | 在選單項上:選中這一項。在子選單標題上:內嵌時展開或收起;浮層模式下打開浮層並聚焦第一項 |
↓ | 橫向選單頂層的子選單標題上:打開浮層並聚焦第一項 |
→ | 向右彈出的子選單標題上(多級浮層裡的、折疊模式頂層的):打開浮層並聚焦第一項 |
Esc | 浮層裡:收起目前這一層浮層,焦點回到它的標題 |
← | 向右彈出的浮層裡:同 Esc |
Home、End | 到目前可見清單的首項、末項,跳過禁用項 |
| 可列印字元 | 按文字前綴跳轉,500ms內連續輸入組成前綴;重複同一字元在匹配項之間循環 |
<script setup lang="ts">
import { ref } from 'vue'
import { HuiMenu, HuiMenuItem, HuiSubMenu, HuiSpace } from '@nscode/handy-ui'
const selected = ref('尚未選擇')
</script>
<template>
<HuiSpace direction="vertical" fill>
<span>Tab進入後試按上下、Home/End或B:{{ selected }}</span>
<HuiMenu :default-openeds="['group']" @select="selected = $event">
<HuiMenuItem index="alpha">Alpha 首頁</HuiMenuItem>
<HuiSubMenu index="group" title="Group 分組">
<HuiMenuItem index="beta">Beta 報表</HuiMenuItem>
<HuiMenuItem index="bravo">Bravo 任務</HuiMenuItem>
<HuiMenuItem index="disabled" disabled>不可選擇</HuiMenuItem>
</HuiSubMenu>
<HuiMenuItem index="charlie">Charlie 設定</HuiMenuItem>
</HuiMenu>
</HuiSpace>
</template>
HuiMenu Props
| 屬性 | 類型 | 預設值 | 說明 |
|---|---|---|---|
| mode | 'horizontal' | 'vertical' | 'vertical' | 選單方向 |
| defaultActive | string | '' | 選取項的 index。執行時修改會選中新的項,並展開它所在的子選單 |
| defaultOpeneds | string[] | [] | 一開始展開的子選單的 index。內容變了時,展開的子選單重置成新的清單 |
| collapse | boolean | false | 是否折疊(只在縱向選單上使用)。折疊後寬 64px,頂層只顯示圖示 |
| backgroundColor | string | - | 選單的背景色,浮層也用這個顏色 |
| textColor | string | - | 選單的文字色,浮層也用這個顏色 |
| activeTextColor | string | - | 選取項和它所在子選單標題的文字色。不傳時用主色 |
| router | boolean | false | 點擊時呼叫 $router.push(route ?? index),成功後按落地路由更新醒目狀態 |
| uniqueOpened | boolean | false | 是否只保持一個子選單展開 |
HuiSubMenu Props
| 屬性 | 類型 | 預設值 | 說明 |
|---|---|---|---|
| index | string | - | 唯一標識,必填 |
| title | string | '' | 標題文字。寫了 title 插槽時不顯示 |
| icon | string | - | 標題前的圖示名(HuiIcon 的 name),折疊模式下頂層只顯示它 |
| disabled | boolean | false | 是否禁用 |
| popperClass | string | '' | 加在子選單清單 ul 上的類名。浮層掛在 body 下,樣式要寫成全域樣式 |
HuiMenuItem Props
| 屬性 | 類型 | 預設值 | 說明 |
|---|---|---|---|
| index | string | - | 唯一標識,必填 |
| route | string | Record<string, unknown> | - | 路由目標。HuiMenu 開了 router 時,點擊後傳給 $router.push |
| icon | string | - | 文字前的圖示名(HuiIcon 的 name),折疊模式下頂層只顯示它 |
| disabled | boolean | false | 是否禁用 |
HuiMenu Events
| 事件 | 回呼參數 | 說明 |
|---|---|---|
| select | (index: string, indexPath: string[], item: MenuItemContext) | 點選單項(或按 Enter、空白)時立即觸發,不代表路由導航成功,點已選項也觸發。indexPath 是所在的各級子選單 index,不包含自己 |
| open | (index: string, indexPath: string[]) | 子選單展開時觸發。indexPath 是這個子選單的各級上級子選單的 index |
| close | (index: string, indexPath: string[]) | 子選單收起時觸發,參數同 open |
HuiMenu Slots
| 插槽 | 作用域參數 | 說明 |
|---|---|---|
| default | - | 放 HuiMenuItem、HuiSubMenu |
HuiSubMenu Slots
| 插槽 | 作用域參數 | 說明 |
|---|---|---|
| default | - | 子選單裡的 HuiMenuItem、HuiSubMenu |
| title | - | 標題內容,替換掉圖示和 title 文字,右邊的箭頭保留 |
HuiMenuItem Slots
| 插槽 | 作用域參數 | 說明 |
|---|---|---|
| default | - | 選單項的文字 |
| title | - | 選單項的文字,寫了它時不顯示預設插槽。折疊時頂層隱藏 |
HuiMenu 暴露的屬性和方法
透過元件的 ref 讀取、呼叫。
| 名稱 | 類型 | 說明 |
|---|---|---|
| activeIndex | string | 目前選取項的 index |
| openedMenus | Set<string> | 目前展開的子選單的 index |
| open | (index: string, indexPath: string[]) => void | 展開子選單並觸發 open,已經展開時什麼也不做。不檢查禁用,也不展開上級 |
| close | (index: string, indexPath: string[]) => void | 收起子選單並觸發 close,已經收起時什麼也不做 |
類型
import type {
MenuMode,
MenuRoute,
MenuProps,
SubMenuProps,
MenuItemProps,
MenuItemContext
} from '@nscode/handy-ui'
import type { Ref } from 'vue'
type MenuMode = 'horizontal' | 'vertical'
type MenuRoute = string | Record<string, unknown>
interface MenuProps {
mode?: MenuMode
defaultActive?: string
defaultOpeneds?: string[]
collapse?: boolean
backgroundColor?: string
textColor?: string
activeTextColor?: string
router?: boolean
uniqueOpened?: boolean
}
interface SubMenuProps {
index: string
title?: string
disabled?: boolean
popperClass?: string
icon?: string
}
interface MenuItemProps {
index: string
route?: MenuRoute
disabled?: boolean
icon?: string
}
/** select 事件的第三個參數 */
interface MenuItemContext {
index: string
rootMenu: MenuContext
parentMenu: SubMenuContext | null
active: Ref<boolean>
disabled: Ref<boolean>
/** 所在的各級子選單的 index,不包含自己 */
indexPath: string[]
route?: MenuRoute
}
另外還導出了 MenuEmits、MenuContext、SubMenuContext 和注入用的 MENU_INJECTION_KEY、SUB_MENU_INJECTION_KEY,自己寫和 HuiMenu 配合的子元件時才用得到。