Cascader 級聯選擇器
從有層級關係的資料裡逐級選擇,例如省 / 市 / 區、部門 / 小組。層級不深、每級選項不多時使用;層級很深或者需要同時看到整棵樹時用 HuiTreeSelect。
引入
import { HuiCascader } from '@nscode/handy-ui'
基礎用法
options 傳層級資料,v-model 綁定的是從第一級到選中節點的路徑(每一級的 value 組成的陣列)。預設只能選最後一級,選中後下拉面板關閉,輸入框裡顯示完整路徑。沒有選中時顯示 placeholder(預設“請選擇”)。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiCascader, HuiSpace } from '@nscode/handy-ui'
import type { CascaderOption } from '@nscode/handy-ui'
const value = ref<(string | number)[] | null>()
const other = ref<(string | number)[] | null>()
const options: CascaderOption[] = [
{
value: 'beijing',
label: '北京',
children: [
{
value: 'haidian',
label: '海淀區',
children: [
{ value: 'zhongguancun', label: '中關村' },
{ value: 'wudaokou', label: '五道口' }
]
},
{ value: 'dongcheng', label: '東城區' }
]
},
{
value: 'guangzhou',
label: '廣州',
children: [
{ value: 'tianhe', label: '天河區' },
{ value: 'yuexiu', label: '越秀區' }
]
}
]
</script>
<template>
<!-- 選中“五道口”後 value 是 ['beijing', 'haidian', 'wudaokou'] -->
<HuiSpace direction="vertical" align="start">
<HuiSpace wrap>
<HuiCascader v-model="value" :options="options" style="width: 260px" />
<HuiCascader
v-model="other"
:options="options"
placeholder="請選擇所在地區"
style="width: 260px"
/>
</HuiSpace>
<span>選中的值:{{ JSON.stringify(value) ?? 'undefined' }}</span>
</HuiSpace>
</template>
展開方式
trigger 決定怎樣展開下一級:click(預設)是點擊節點展開,hover 是滑鼠移到節點上就展開,選中仍然需要點擊。expand-trigger 和 trigger 是同一個意思,兩個都傳時以 expand-trigger 為準。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiCascader, HuiSpace } from '@nscode/handy-ui'
import type { CascaderOption } from '@nscode/handy-ui'
const value = ref<(string | number)[] | null>()
const hoverValue = ref<(string | number)[] | null>()
const options: CascaderOption[] = [
{
value: 'beijing',
label: '北京',
children: [
{
value: 'haidian',
label: '海淀區',
children: [
{ value: 'zhongguancun', label: '中關村' },
{ value: 'wudaokou', label: '五道口' }
]
},
{ value: 'dongcheng', label: '東城區' }
]
},
{
value: 'guangzhou',
label: '廣州',
children: [
{ value: 'tianhe', label: '天河區' },
{ value: 'yuexiu', label: '越秀區' }
]
}
]
</script>
<template>
<HuiSpace wrap>
<HuiCascader
v-model="value"
:options="options"
trigger="click"
placeholder="點擊展開(click)"
style="width: 260px"
/>
<HuiCascader
v-model="hoverValue"
:options="options"
trigger="hover"
placeholder="暫留展開(hover)"
style="width: 260px"
/>
</HuiSpace>
</template>
只顯示最後一級
show-all-levels 預設是 true,輸入框和多選標籤裡顯示完整路徑。:show-all-levels="false" 時只顯示選中節點自己的文字。綁定值不受影響,仍然是完整路徑。上面一行是預設,下面一行是 false:
<script setup lang="ts">
import { ref } from 'vue'
import { HuiCascader, HuiSpace } from '@nscode/handy-ui'
import type { CascaderOption } from '@nscode/handy-ui'
const value = ref<(string | number)[] | null>(['beijing', 'haidian', 'wudaokou'])
const values = ref<(string | number)[][]>([
['beijing', 'haidian', 'wudaokou'],
['guangzhou', 'tianhe']
])
const options: CascaderOption[] = [
{
value: 'beijing',
label: '北京',
children: [
{
value: 'haidian',
label: '海淀區',
children: [
{ value: 'zhongguancun', label: '中關村' },
{ value: 'wudaokou', label: '五道口' }
]
},
{ value: 'dongcheng', label: '東城區' }
]
},
{
value: 'guangzhou',
label: '廣州',
children: [
{ value: 'tianhe', label: '天河區' },
{ value: 'yuexiu', label: '越秀區' }
]
}
]
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiSpace wrap>
<span class="row-label">true</span>
<HuiCascader v-model="value" :options="options" style="width: 220px" />
<HuiCascader v-model="values" :options="options" multiple style="width: 320px" />
</HuiSpace>
<HuiSpace wrap>
<span class="row-label">false</span>
<HuiCascader
v-model="value"
:options="options"
:show-all-levels="false"
style="width: 220px"
/>
<HuiCascader
v-model="values"
:options="options"
multiple
:show-all-levels="false"
style="width: 320px"
/>
</HuiSpace>
</HuiSpace>
</template>
<style scoped>
.row-label {
display: inline-block;
width: 56px;
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
</style>
自訂分隔符
separator 設定路徑裡各級文字之間的分隔符,預設是 /,前後不帶空白。輸入框、多選標籤和搜尋結果裡的路徑都用它。需要空白時寫在分隔符裡,例如 ' / '。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiCascader, HuiSpace } from '@nscode/handy-ui'
import type { CascaderOption } from '@nscode/handy-ui'
const value = ref<(string | number)[] | null>(['beijing', 'haidian', 'wudaokou'])
const options: CascaderOption[] = [
{
value: 'beijing',
label: '北京',
children: [
{
value: 'haidian',
label: '海淀區',
children: [
{ value: 'zhongguancun', label: '中關村' },
{ value: 'wudaokou', label: '五道口' }
]
},
{ value: 'dongcheng', label: '東城區' }
]
},
{
value: 'guangzhou',
label: '廣州',
children: [
{ value: 'tianhe', label: '天河區' },
{ value: 'yuexiu', label: '越秀區' }
]
}
]
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiSpace wrap>
<span class="row-label">'/'</span>
<HuiCascader v-model="value" :options="options" style="width: 260px" />
</HuiSpace>
<HuiSpace wrap>
<span class="row-label">' / '</span>
<HuiCascader v-model="value" :options="options" separator=" / " style="width: 260px" />
</HuiSpace>
<HuiSpace wrap>
<span class="row-label">' > '</span>
<HuiCascader v-model="value" :options="options" separator=" > " style="width: 260px" />
</HuiSpace>
<HuiSpace wrap>
<span class="row-label">'-'</span>
<HuiCascader v-model="value" :options="options" separator="-" style="width: 260px" />
</HuiSpace>
</HuiSpace>
</template>
<style scoped>
.row-label {
display: inline-block;
width: 56px;
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
white-space: pre;
}
</style>
可清除
加上 clearable 後,有值時右側顯示清除按鈕(沒值或禁用時不顯示)。點擊後單選的值變成 null,多選的值變成 [],依次觸發 update:modelValue、clear、change。父元件接受清除後才改變顯示;null 可保留 JSON 序列化欄位,路徑中的 0、空字串仍是真實節點值。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiCascader, HuiSpace } from '@nscode/handy-ui'
import type { CascaderOption } from '@nscode/handy-ui'
const value = ref<(string | number)[] | null>(['beijing', 'haidian', 'wudaokou'])
const values = ref<(string | number)[][]>([['guangzhou', 'tianhe']])
const options: CascaderOption[] = [
{
value: 'beijing',
label: '北京',
children: [
{
value: 'haidian',
label: '海淀區',
children: [
{ value: 'zhongguancun', label: '中關村' },
{ value: 'wudaokou', label: '五道口' }
]
},
{ value: 'dongcheng', label: '東城區' }
]
},
{
value: 'guangzhou',
label: '廣州',
children: [
{ value: 'tianhe', label: '天河區' },
{ value: 'yuexiu', label: '越秀區' }
]
}
]
</script>
<template>
<HuiSpace wrap>
<HuiCascader v-model="value" :options="options" clearable style="width: 260px" />
<HuiCascader v-model="values" :options="options" multiple clearable style="width: 320px" />
</HuiSpace>
<p style="margin-top: 12px">
單選:{{ JSON.stringify(value) ?? 'undefined' }};多選:{{ JSON.stringify(values) }}
</p>
</template>
禁用
disabled 禁用整個選擇器:不能展開,有值時也不顯示清除按鈕,多選的標籤上沒有叉。選項資料裡的 disabled: true 禁用這個節點:它不能選也不能展開,所以它下面的節點也都選不到;多選時勾選父節點也不會勾上它。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiCascader, HuiSpace } from '@nscode/handy-ui'
import type { CascaderOption } from '@nscode/handy-ui'
const empty = ref<(string | number)[] | null>()
const single = ref<(string | number)[] | null>(['beijing', 'haidian'])
const multi = ref<(string | number)[][]>([
['beijing', 'haidian'],
['beijing', 'dongcheng']
])
const value = ref<(string | number)[] | null>()
const values = ref<(string | number)[][]>([])
const options: CascaderOption[] = [
{
value: 'beijing',
label: '北京',
children: [
{ value: 'haidian', label: '海淀區' },
{ value: 'chaoyang', label: '朝陽區(禁用)', disabled: true },
{ value: 'dongcheng', label: '東城區' }
]
},
{ value: 'shanghai', label: '上海(禁用)', disabled: true }
]
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiSpace wrap>
<span class="row-label">整體禁用</span>
<HuiCascader v-model="empty" :options="options" disabled style="width: 200px" />
<HuiCascader v-model="single" :options="options" disabled clearable style="width: 200px" />
<HuiCascader v-model="multi" :options="options" multiple disabled style="width: 300px" />
</HuiSpace>
<HuiSpace wrap>
<span class="row-label">選項禁用</span>
<HuiCascader v-model="value" :options="options" style="width: 200px" />
<HuiCascader v-model="values" :options="options" multiple style="width: 300px" />
</HuiSpace>
</HuiSpace>
</template>
<style scoped>
.row-label {
display: inline-block;
width: 56px;
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
</style>
可選任意一級
加上 check-strictly 後每一級都可以選。點還有下一級的節點會選中它並展開下一級,下拉面板不關閉;點到最後一級才關閉。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiCascader } from '@nscode/handy-ui'
import type { CascaderOption } from '@nscode/handy-ui'
const value = ref<(string | number)[] | null>()
const options: CascaderOption[] = [
{
value: 'beijing',
label: '北京',
children: [
{
value: 'haidian',
label: '海淀區',
children: [
{ value: 'zhongguancun', label: '中關村' },
{ value: 'wudaokou', label: '五道口' }
]
},
{ value: 'dongcheng', label: '東城區' }
]
},
{
value: 'guangzhou',
label: '廣州',
children: [
{ value: 'tianhe', label: '天河區' },
{ value: 'yuexiu', label: '越秀區' }
]
}
]
</script>
<template>
<HuiCascader v-model="value" :options="options" check-strictly clearable />
</template>
多選
加上 multiple 後每個節點前面有核取方塊,綁定值是路徑的陣列,選中的項顯示成標籤。
- 勾選父節點等於勾選它下面所有沒禁用的最後一級,綁定值裡只存最後一級的路徑;只勾了一部分時父節點顯示半選。
- 點父節點的文字只展開下一級,點核取方塊才勾選。
- 點標籤上的叉移除這一項。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiCascader } from '@nscode/handy-ui'
import type { CascaderOption } from '@nscode/handy-ui'
const value = ref<(string | number)[][]>([
['beijing', 'haidian', 'wudaokou'],
['guangzhou', 'tianhe']
])
const options: CascaderOption[] = [
{
value: 'beijing',
label: '北京',
children: [
{
value: 'haidian',
label: '海淀區',
children: [
{ value: 'zhongguancun', label: '中關村' },
{ value: 'wudaokou', label: '五道口' }
]
},
{ value: 'dongcheng', label: '東城區' }
]
},
{
value: 'guangzhou',
label: '廣州',
children: [
{ value: 'tianhe', label: '天河區' },
{ value: 'yuexiu', label: '越秀區' }
]
}
]
</script>
<template>
<HuiCascader v-model="value" :options="options" multiple clearable style="width: 420px" />
</template>
同時加上 check-strictly 時父子不再關聯,每一級單獨勾選,勾了父節點綁定值裡存的就是父節點的路徑。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiCascader } from '@nscode/handy-ui'
import type { CascaderOption } from '@nscode/handy-ui'
const value = ref<(string | number)[][]>([])
const options: CascaderOption[] = [
{
value: 'beijing',
label: '北京',
children: [
{
value: 'haidian',
label: '海淀區',
children: [
{ value: 'zhongguancun', label: '中關村' },
{ value: 'wudaokou', label: '五道口' }
]
},
{ value: 'dongcheng', label: '東城區' }
]
},
{
value: 'guangzhou',
label: '廣州',
children: [
{ value: 'tianhe', label: '天河區' },
{ value: 'yuexiu', label: '越秀區' }
]
}
]
</script>
<template>
<HuiCascader v-model="value" :options="options" multiple check-strictly />
</template>
折疊標籤
多選時預設開啟 collapse-tags,顯示前 max-collapse-tags 個標籤(預設 3 個),其餘折疊成 +N。:collapse-tags="false" 顯示全部標籤;collapse-tags-tooltip 預設關閉,開啟後將滑鼠停在 +N 上,可查看被折疊的選項。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiCascader, HuiSpace } from '@nscode/handy-ui'
import type { CascaderOption } from '@nscode/handy-ui'
const value = ref<(string | number)[][]>([
['beijing', 'haidian', 'zhongguancun'],
['beijing', 'haidian', 'wudaokou'],
['beijing', 'dongcheng'],
['guangzhou', 'tianhe']
])
const options: CascaderOption[] = [
{
value: 'beijing',
label: '北京',
children: [
{
value: 'haidian',
label: '海淀區',
children: [
{ value: 'zhongguancun', label: '中關村' },
{ value: 'wudaokou', label: '五道口' }
]
},
{ value: 'dongcheng', label: '東城區' }
]
},
{
value: 'guangzhou',
label: '廣州',
children: [
{ value: 'tianhe', label: '天河區' },
{ value: 'yuexiu', label: '越秀區' }
]
}
]
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiCascader v-model="value" :options="options" multiple collapse-tags />
<HuiCascader v-model="value" :options="options" multiple collapse-tags :max-collapse-tags="2" />
<HuiCascader v-model="value" :options="options" multiple collapse-tags collapse-tags-tooltip />
</HuiSpace>
</template>
可搜尋
加上 filterable 後,展開時輸入框可以打字。搜尋結果是一個清單,每一行顯示完整路徑;路徑上任意一級的文字包含關鍵字就算匹配(不區分大小寫)。結果裡只列出能選的節點:預設是最後一級,check-strictly 時是所有節點。多選時搜尋結果前面也有核取方塊。
下面依次是單選、多選、check-strictly,都輸入“海淀”對比結果:
<script setup lang="ts">
import { ref } from 'vue'
import { HuiCascader, HuiSpace } from '@nscode/handy-ui'
import type { CascaderOption } from '@nscode/handy-ui'
const value = ref<(string | number)[] | null>()
const values = ref<(string | number)[][]>([])
const strictValue = ref<(string | number)[] | null>()
const options: CascaderOption[] = [
{
value: 'beijing',
label: '北京',
children: [
{
value: 'haidian',
label: '海淀區',
children: [
{ value: 'zhongguancun', label: '中關村' },
{ value: 'wudaokou', label: '五道口' }
]
},
{ value: 'dongcheng', label: '東城區' }
]
},
{
value: 'guangzhou',
label: '廣州',
children: [
{ value: 'tianhe', label: '天河區' },
{ value: 'yuexiu', label: '越秀區' }
]
}
]
</script>
<template>
<HuiSpace wrap>
<HuiCascader
v-model="value"
:options="options"
filterable
placeholder="單選"
style="width: 220px"
/>
<HuiCascader
v-model="values"
:options="options"
filterable
multiple
placeholder="多選"
style="width: 300px"
/>
<HuiCascader
v-model="strictValue"
:options="options"
filterable
check-strictly
placeholder="任意一級"
style="width: 220px"
/>
</HuiSpace>
</template>
debounce 設定停止輸入多少毫秒後才開始搜尋,預設 300,小於等於 0 時不防抖。before-filter 在每次搜尋前呼叫,回傳 false(或者 resolve 為 false 的 Promise)時不搜尋,並清除輸入的內容。
左邊防抖 500 毫秒,輸入裡帶數字時不搜尋;右邊的 before-filter 回傳 Promise,用 setTimeout 模擬 500 毫秒的介面驗證,輸入原始觸發字串 测试 會被攔下:
<script setup lang="ts">
import { ref } from 'vue'
import { HuiCascader, HuiSpace } from '@nscode/handy-ui'
import type { CascaderOption } from '@nscode/handy-ui'
const value = ref<(string | number)[] | null>()
const asyncValue = ref<(string | number)[] | null>()
const options: CascaderOption[] = [
{
value: 'beijing',
label: '北京',
children: [
{
value: 'haidian',
label: '海淀區',
children: [
{ value: 'zhongguancun', label: '中關村' },
{ value: 'wudaokou', label: '五道口' }
]
},
{ value: 'dongcheng', label: '東城區' }
]
},
{
value: 'guangzhou',
label: '廣州',
children: [
{ value: 'tianhe', label: '天河區' },
{ value: 'yuexiu', label: '越秀區' }
]
}
]
// 輸入裡帶數字時不搜尋
const beforeFilter = (query: string) => !/\d/.test(query)
// 模擬介面驗證關鍵字
const checkKeyword = (query: string) =>
new Promise<boolean>((resolve) => {
setTimeout(() => resolve(!query.includes('测试')), 500)
})
</script>
<template>
<HuiSpace wrap>
<HuiCascader
v-model="value"
:options="options"
filterable
:debounce="500"
:before-filter="beforeFilter"
placeholder="帶數字時不搜尋"
style="width: 240px"
/>
<HuiCascader
v-model="asyncValue"
:options="options"
filterable
:before-filter="checkKeyword"
placeholder="輸入「测试」會被攔下(原始觸發字串)"
style="width: 240px"
/>
</HuiSpace>
</template>
非同步搜尋檢查與過期結果
beforeFilter 只有 false(或 resolve false)攔截,undefined 放行。目前檢查拋錯或 reject 時接住異常,開發環境輸出診斷,並像 false 一樣清除目前輸入和已應用的搜尋詞。選擇值不變。
每次輸入立即使舊檢查失效,不等下一次防抖開始;即使經歷 A→B→A、清除、關閉重開,舊檢查也不能清掉新詞或提前應用結果。關閉動畫結束後恢復面板的時機保持不變。取消只廢棄結果,不終止業務請求,因此下面的記錄仍可能記錄舊檢查完成。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiCascader, HuiSpace } from '@nscode/handy-ui'
import type { CascaderOption } from '@nscode/handy-ui'
const guardValue = ref<(string | number)[] | null>()
const guardOptions: CascaderOption[] = [
{ value: 'slow', label: '慢結果' },
{ value: 'fast', label: '快結果' },
{ value: 'sync', label: '同步結果' }
]
const guardMessages = ref<string[]>([])
const recordGuard = (message: string) => {
guardMessages.value = [message, ...guardMessages.value].slice(0, 8)
}
const guardBeforeFilter = (query: string): boolean | void | Promise<boolean | void> => {
recordGuard(`開始檢查:${query}`)
if (query.includes('同步')) {
recordGuard(`同步放行:${query}`)
return
}
return new Promise<boolean | void>((resolve, reject) => {
setTimeout(
() => {
if (query.includes('异常')) {
recordGuard(`檢查異常:${query}`)
reject(new Error('示範搜尋檢查異常'))
return
}
const allowed = !query.includes('拒绝')
recordGuard(`檢查完成:${query},${allowed ? '放行' : '攔截'}`)
resolve(allowed ? undefined : false)
},
query.includes('慢') ? 1200 : 250
)
})
}
</script>
<template>
<HuiSpace direction="vertical" fill>
<span>依次輸入“慢”“快”:舊檢查完成不會覆蓋新結果;“同步”返回 undefined 放行。</span>
<span>輸入原始觸發字串「拒绝」或「异常」:僅目前檢查攔截時清除搜尋,選擇值不變。</span>
<HuiCascader
v-model="guardValue"
:options="guardOptions"
:before-filter="guardBeforeFilter"
:debounce="200"
filterable
placeholder="輸入慢、快、同步、拒绝或异常(保留原始觸發字串)"
style="width: 360px; max-width: 100%; flex: none"
/>
<span>目前選擇:{{ guardValue?.join('/') || '未選擇' }}</span>
<ol>
<li v-for="(message, index) in guardMessages" :key="index">{{ message }}</li>
</ol>
</HuiSpace>
</template>
尺寸
size 有 large、default、small 三種,和同尺寸的 HuiInput、HuiButton 一致:高度 40 / 32 / 24px,字級 16 / 14 / 12px,圓角 8 / 6 / 4px。下拉面板也跟著變,選項列高 40 / 約 36 / 28px,字級 16 / 14 / 12px,左右內距 16 / 12 / 8px,選項文字和輸入框裡的文字左邊齊平;多選時選項前面的核取方塊也跟著 Cascader 的尺寸(方框 18 / 16 / 14px),不跟著外面的 Form。不寫 size 時依次跟隨所在的 HuiFormItem、HuiForm、HuiConfigProvider 的 size,都沒有時是 default。
每一行是一種尺寸,依次是單選(可清除)、多選、同尺寸的按鈕:
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiCascader, HuiSpace } from '@nscode/handy-ui'
import type { CascaderOption } from '@nscode/handy-ui'
const value = ref<(string | number)[] | null>(['beijing', 'dongcheng'])
const values = ref<(string | number)[][]>([['guangzhou', 'tianhe']])
const options: CascaderOption[] = [
{
value: 'beijing',
label: '北京',
children: [
{
value: 'haidian',
label: '海淀區',
children: [
{ value: 'zhongguancun', label: '中關村' },
{ value: 'wudaokou', label: '五道口' }
]
},
{ value: 'dongcheng', label: '東城區' }
]
},
{
value: 'guangzhou',
label: '廣州',
children: [
{ value: 'tianhe', label: '天河區' },
{ value: 'yuexiu', label: '越秀區' }
]
}
]
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiSpace wrap>
<span class="row-label">large</span>
<HuiCascader v-model="value" :options="options" size="large" clearable style="width: 200px" />
<HuiCascader v-model="values" :options="options" size="large" multiple style="width: 260px" />
<HuiButton size="large">按鈕</HuiButton>
</HuiSpace>
<HuiSpace wrap>
<span class="row-label">default</span>
<HuiCascader v-model="value" :options="options" clearable style="width: 200px" />
<HuiCascader v-model="values" :options="options" multiple style="width: 260px" />
<HuiButton>按鈕</HuiButton>
</HuiSpace>
<HuiSpace wrap>
<span class="row-label">small</span>
<HuiCascader v-model="value" :options="options" size="small" clearable style="width: 200px" />
<HuiCascader v-model="values" :options="options" size="small" multiple style="width: 260px" />
<HuiButton size="small">按鈕</HuiButton>
</HuiSpace>
</HuiSpace>
</template>
<style scoped>
.row-label {
display: inline-block;
width: 56px;
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
</style>
自訂欄位名
資料裡的欄位名不是 value、label、children、disabled 時,用 props 指定對應的欄位名。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiCascader } from '@nscode/handy-ui'
import type { CascaderOption } from '@nscode/handy-ui'
const value = ref<(string | number)[] | null>()
const departments = [
{
code: 'dev',
name: '研发部',
items: [
{ code: 'fe', name: '前端组' },
{ code: 'be', name: '后端组' },
{ code: 'qa', name: '测试组(停用)', locked: true }
]
},
{ code: 'ops', name: '运维部' }
] as unknown as CascaderOption[]
const fieldNames = { value: 'code', label: 'name', children: 'items', disabled: 'locked' }
</script>
<template>
<HuiCascader v-model="value" :options="departments" :props="fieldNames" style="width: 280px" />
</template>
空資料提示
options 為空,或者搜尋後沒有結果時,下拉面板顯示“暫無資料”。用 empty 插槽可以換成別的內容。左邊是沒有選項,右邊可以搜一個不存在的詞看看:
<script setup lang="ts">
import { ref } from 'vue'
import { HuiCascader, HuiSpace } from '@nscode/handy-ui'
import type { CascaderOption } from '@nscode/handy-ui'
const value = ref<(string | number)[] | null>()
const area = ref<(string | number)[] | null>()
const options: CascaderOption[] = [
{
value: 'guangzhou',
label: '廣州',
children: [
{ value: 'tianhe', label: '天河區' },
{ value: 'yuexiu', label: '越秀區' }
]
}
]
</script>
<template>
<HuiSpace wrap>
<HuiCascader v-model="value" :options="[]" style="width: 240px">
<template #empty>還沒有可選的內容</template>
</HuiCascader>
<HuiCascader
v-model="area"
:options="options"
filterable
placeholder="輸入“深圳”試試"
style="width: 240px"
>
<template #empty>沒有找到這個地區</template>
</HuiCascader>
</HuiSpace>
</template>
事件
change 在使用者選擇、勾選、移除標籤或清除時,回報本次請求值,實際畫面仍遵從父元件回填;expand-change 在展開路徑變化時觸發;visible-change 在下拉層展開、收起時觸發;remove-tag 僅在點擊標籤上的叉時觸發,取消勾選透過 change 觀察;clear 在點擊清除按鈕或呼叫 clear() 時觸發。最近的事件顯示在下方:
<script setup lang="ts">
import { ref } from 'vue'
import { HuiCascader, HuiSpace } from '@nscode/handy-ui'
import type { CascaderOption } from '@nscode/handy-ui'
const values = ref<(string | number)[][]>([['beijing', 'dongcheng']])
const logs = ref<string[]>([])
const options: CascaderOption[] = [
{
value: 'beijing',
label: '北京',
children: [
{
value: 'haidian',
label: '海淀區',
children: [
{ value: 'zhongguancun', label: '中關村' },
{ value: 'wudaokou', label: '五道口' }
]
},
{ value: 'dongcheng', label: '東城區' }
]
},
{
value: 'guangzhou',
label: '廣州',
children: [
{ value: 'tianhe', label: '天河區' },
{ value: 'yuexiu', label: '越秀區' }
]
}
]
const log = (text: string) => {
logs.value = [text, ...logs.value].slice(0, 6)
}
const onChange = (val: unknown) => log(`change:${JSON.stringify(val)}`)
const onExpandChange = (path: (string | number)[]) =>
log(`expand-change:${JSON.stringify(path)}`)
const onVisibleChange = (visible: boolean) => log(`visible-change:${visible}`)
const onRemoveTag = (path: (string | number)[]) => log(`remove-tag:${JSON.stringify(path)}`)
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiCascader
v-model="values"
:options="options"
multiple
clearable
style="max-width: 400px"
@change="onChange"
@expand-change="onExpandChange"
@visible-change="onVisibleChange"
@remove-tag="onRemoveTag"
@clear="log('clear')"
/>
<div class="logs">
<div v-if="logs.length === 0">還沒有觸發事件</div>
<div v-for="(item, index) in logs" :key="index">{{ item }}</div>
</div>
</HuiSpace>
</template>
<style scoped>
.logs {
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
</style>
呼叫方法
透過 ref 呼叫 focus()、blur()。ref 上的 selectedNodes 是目前選取項的清單,activePath 是下拉面板目前展開到的路徑:
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiCascader, HuiSpace } from '@nscode/handy-ui'
import type { CascaderOption } from '@nscode/handy-ui'
const cascaderRef = ref<InstanceType<typeof HuiCascader>>()
const value = ref<(string | number)[] | null>(['beijing', 'haidian', 'wudaokou'])
const options: CascaderOption[] = [
{
value: 'beijing',
label: '北京',
children: [
{
value: 'haidian',
label: '海淀區',
children: [
{ value: 'zhongguancun', label: '中關村' },
{ value: 'wudaokou', label: '五道口' }
]
},
{ value: 'dongcheng', label: '東城區' }
]
},
{
value: 'guangzhou',
label: '廣州',
children: [
{ value: 'tianhe', label: '天河區' },
{ value: 'yuexiu', label: '越秀區' }
]
}
]
</script>
<template>
<HuiSpace wrap>
<HuiCascader ref="cascaderRef" v-model="value" :options="options" style="width: 260px" />
<HuiButton @click="cascaderRef?.focus()">聚焦(focus)</HuiButton>
<HuiButton @click="cascaderRef?.blur()">失焦(blur)</HuiButton>
</HuiSpace>
<p style="margin-top: 12px">
selectedNodes:{{
cascaderRef?.selectedNodes.map((item) => item.pathLabels.join(' / ')).join('、')
}}<br />
activePath:{{ JSON.stringify(cascaderRef?.activePath ?? []) }}
</p>
</template>
在表單裡使用
放在 HuiFormItem 裡時,值變化觸發 change 規則,收起下拉面板觸發 blur 規則;不寫 size、disabled 時跟隨表單。下面的地區展開後不選直接收起,就會提示必填:
<script setup lang="ts">
import { reactive, ref } from 'vue'
import {
HuiButton,
HuiCascader,
HuiForm,
HuiFormItem,
HuiMessage,
HuiSpace
} from '@nscode/handy-ui'
import type { CascaderOption, FormRule } from '@nscode/handy-ui'
const formRef = ref<InstanceType<typeof HuiForm>>()
const model = reactive<{ area?: (string | number)[]; areas: (string | number)[][] }>({
area: undefined,
areas: []
})
const rules: Record<string, FormRule[]> = {
area: [{ required: true, message: '請選擇地區', trigger: ['change', 'blur'] }],
areas: [{ required: true, message: '至少選一個服務範圍', trigger: 'change' }]
}
const options: CascaderOption[] = [
{
value: 'guangzhou',
label: '廣州',
children: [
{ value: 'tianhe', label: '天河區' },
{ value: 'yuexiu', label: '越秀區' }
]
},
{
value: 'shenzhen',
label: '深圳',
children: [
{ value: 'nanshan', label: '南山區' },
{ value: 'futian', label: '福田區' }
]
}
]
const submit = async () => {
const result = await formRef.value?.validate()
if (result?.valid) HuiMessage.success('驗證通過')
}
</script>
<template>
<HuiForm ref="formRef" :model="model" :rules="rules" label-width="80px" style="max-width: 420px">
<HuiFormItem label="地區" prop="area">
<HuiCascader v-model="model.area" :options="options" clearable />
</HuiFormItem>
<HuiFormItem label="服務範圍" prop="areas">
<HuiCascader v-model="model.areas" :options="options" multiple clearable />
</HuiFormItem>
<HuiFormItem>
<HuiSpace>
<HuiButton type="primary" @click="submit">提交</HuiButton>
<HuiButton @click="formRef?.resetFields()">重置</HuiButton>
</HuiSpace>
</HuiFormItem>
</HuiForm>
</template>
鍵盤操作
選擇器可以用 Tab 聚焦,聚焦後:
| 按鍵 | 作用 |
|---|---|
| Enter | 沒展開時展開;展開後相當於點一下目前停留的節點(展開下一級或選中) |
| 空白 | 沒展開時展開;展開後單選相當於點擊,多選是勾選或取消勾選目前停留的節點 |
| ↓、↑ | 沒展開時展開;展開後在同一列裡移動,跳過禁用的節點,到頭後循環 |
| → | 展開目前節點,停到它的第一個子節點上 |
| ← | 回到上一級 |
| Home、End | 僅不可搜尋(filterable=false)且已展開時,移到目前列第一個、末個可用節點 |
| Esc | 收起下拉面板,焦點回到選擇器 |
| Tab | 收起下拉面板,焦點移到下一個元素 |
搜尋時上下鍵在搜尋結果裡循環移動,Enter 選中;Home、End、空白以及編輯文字時的左右鍵留給搜尋框。輸入法組合中的按鍵、鍵碼229及帶Alt、Ctrl、Meta的按鍵不觸發導航或選擇。
醒目按完整路徑保存。同一查詢下,父元件重新呈現、等值資料回填或選項重排不會把仍有效的醒目重置到首項;應用新搜尋詞時回到第一個可用結果。目前項被刪除或禁用時,優先同列原位置及後方,再找前方可用項;該列或父路徑失效才逐層回退。資料更新只調整醒目,不主動移動真實焦點或發出選擇事件。
自持與受控
未傳modelValue或僅監聽更新時,單選從null、多選從空陣列保存內部狀態;顯式傳入即受控,undefined為空。顯示、標籤、選中狀態和表單驗證使用實際值。父拒絕選擇、移除或清除時保留父選擇,多選連續請求也從父實際路徑重新計算。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiCascader, HuiSpace } from '@nscode/handy-ui'
import type { CascaderOption, CascaderProps } from '@nscode/handy-ui'
const cascadeOptions: CascaderOption[] = [
{ value: 'a', label: '甲', children: [{ value: 'a1', label: '甲一' }] },
{ value: 'b', label: '乙' },
{ value: 'c', label: '丙' }
]
const cascadeSingle = ref<CascaderProps['modelValue']>(['a', 'a1'])
const cascadeMultiple = ref<CascaderProps['modelValue']>([['a', 'a1']])
const cascadeRedraw = ref(0)
const cascadeSingleLast = ref('尚無')
const cascadeMultipleLast = ref('尚無')
const recordCascadeSingle = (value: CascaderProps['modelValue']) => {
cascadeSingleLast.value = JSON.stringify(value) ?? 'undefined'
}
const recordCascadeMultiple = (value: CascaderProps['modelValue']) => {
cascadeMultipleLast.value = JSON.stringify(value) ?? 'undefined'
}
</script>
<template>
<HuiSpace class="cascader-q1-demo" direction="vertical" fill :data-parent="cascadeRedraw">
<HuiSpace wrap>
<HuiButton class="cascader-redraw" @click="cascadeRedraw++"
>父級重新呈現 {{ cascadeRedraw }}</HuiButton
>
<span>選擇乙後重新呈現父級;固定值和顯式空值保持父元件實際選擇。</span>
</HuiSpace>
<HuiSpace wrap align="start">
<HuiSpace class="cascader-single" direction="vertical" style="width: 370px; max-width: 100%">
<strong>單選</strong>
<HuiSpace class="cascader-local" direction="vertical" style="width: 100%">
<span>未傳模型</span>
<HuiCascader
:options="cascadeOptions"
style="width: 320px; max-width: 100%"
clearable
filterable
:debounce="0"
/>
</HuiSpace>
<HuiSpace class="cascader-listener" direction="vertical" style="width: 100%">
<span>僅監聽更新</span>
<HuiCascader
@update:model-value="recordCascadeSingle"
:options="cascadeOptions"
style="width: 320px; max-width: 100%"
clearable
filterable
:debounce="0"
/>
</HuiSpace>
<HuiSpace class="cascader-empty" direction="vertical" style="width: 100%">
<span>顯式 undefined</span>
<HuiCascader
:model-value="undefined"
:options="cascadeOptions"
style="width: 320px; max-width: 100%"
clearable
filterable
:debounce="0"
/>
</HuiSpace>
<HuiSpace class="cascader-fixed" direction="vertical" style="width: 100%">
<span>固定甲/甲一,父拒絕</span>
<HuiCascader
:model-value="['a', 'a1']"
:options="cascadeOptions"
style="width: 320px; max-width: 100%"
clearable
filterable
:debounce="0"
/>
</HuiSpace>
<HuiSpace class="cascader-bound" direction="vertical" style="width: 100%">
<span>雙向綁定</span>
<HuiCascader
v-model="cascadeSingle"
:options="cascadeOptions"
style="width: 320px; max-width: 100%"
clearable
filterable
:debounce="0"
/>
</HuiSpace>
<span class="cascader-status"
>監聽請求:{{ cascadeSingleLast }};綁定值:{{ JSON.stringify(cascadeSingle) }}</span
>
</HuiSpace>
<HuiSpace
class="cascader-multiple"
direction="vertical"
style="width: 370px; max-width: 100%"
>
<strong>多選</strong>
<HuiSpace class="cascader-local" direction="vertical" style="width: 100%">
<span>未傳模型</span>
<HuiCascader
multiple
:options="cascadeOptions"
style="width: 320px; max-width: 100%"
clearable
filterable
:debounce="0"
/>
</HuiSpace>
<HuiSpace class="cascader-listener" direction="vertical" style="width: 100%">
<span>僅監聽更新</span>
<HuiCascader
multiple
@update:model-value="recordCascadeMultiple"
:options="cascadeOptions"
style="width: 320px; max-width: 100%"
clearable
filterable
:debounce="0"
/>
</HuiSpace>
<HuiSpace class="cascader-empty" direction="vertical" style="width: 100%">
<span>顯式 undefined</span>
<HuiCascader
multiple
:model-value="undefined"
:options="cascadeOptions"
style="width: 320px; max-width: 100%"
clearable
filterable
:debounce="0"
/>
</HuiSpace>
<HuiSpace class="cascader-fixed" direction="vertical" style="width: 100%">
<span>固定甲/甲一,父拒絕</span>
<HuiCascader
multiple
:model-value="[['a', 'a1']]"
:options="cascadeOptions"
style="width: 320px; max-width: 100%"
clearable
filterable
:debounce="0"
/>
</HuiSpace>
<HuiSpace class="cascader-bound" direction="vertical" style="width: 100%">
<span>雙向綁定</span>
<HuiCascader
multiple
v-model="cascadeMultiple"
:options="cascadeOptions"
style="width: 320px; max-width: 100%"
clearable
filterable
:debounce="0"
/>
</HuiSpace>
<span class="cascader-status"
>監聽請求:{{ cascadeMultipleLast }};綁定值:{{ JSON.stringify(cascadeMultiple) }}</span
>
</HuiSpace>
</HuiSpace>
</HuiSpace>
</template>
公開清除方法
透過元件ref的clear()與清除圖示共用入口:單選請求null、多選請求[],順序為update:modelValue → clear → change。clearable僅控制圖示,關閉圖示時方法仍可主動清除。父拒絕時保持實際路徑、標籤和selectedNodes;禁用、表單唯讀或卸載後無效。同步回呼重入不重複通知,新選擇或卸載會停止舊清除尾部。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiCascader, HuiSpace } from '@nscode/handy-ui'
import type { CascaderExpose, CascaderOption, CascaderProps } from '@nscode/handy-ui'
const options: CascaderOption[] = [
{ value: 0, label: '零', children: [{ value: '', label: '空串' }] },
{ value: 'b', label: '乙' }
]
const single = ref<CascaderProps['modelValue']>([0, ''])
const multiple = ref<CascaderProps['modelValue']>([[0, '']])
const singleRef = ref<CascaderExpose>()
const multipleRef = ref<CascaderExpose>()
const fixedSingleRef = ref<CascaderExpose>()
const fixedMultipleRef = ref<CascaderExpose>()
const notices = ref<Record<string, string[]>>({
single: [],
multiple: [],
fixedSingle: [],
fixedMultiple: []
})
const record = (kind: string, event: string, value?: CascaderProps['modelValue']) => {
notices.value[kind].push(value === undefined ? event : `${event}:${JSON.stringify(value)}`)
}
const reset = () => {
single.value = [0, '']
multiple.value = [[0, '']]
notices.value = { single: [], multiple: [], fixedSingle: [], fixedMultiple: [] }
}
</script>
<template>
<HuiSpace class="cascader-clear-demo" direction="vertical" fill>
<span>方法和圖示共用入口:單選請求null,多選請求[];父拒絕時保持實際路徑。</span>
<HuiSpace class="cascade-clear-single" wrap>
<span>單選父接受</span>
<HuiCascader
ref="singleRef"
v-model="single"
:options="options"
clearable
style="width: 240px"
@update:model-value="record('single', 'update', $event)"
@clear="record('single', 'clear')"
@change="record('single', 'change', $event)"
/>
<HuiButton class="cascade-clear-single-button" @click="singleRef?.clear()"
>單選清除</HuiButton
>
</HuiSpace>
<span class="cascade-clear-single-status"
>模型:{{ JSON.stringify(single) }};{{ notices.single.join(' → ') }}</span
>
<HuiSpace class="cascade-clear-fixed-single" wrap>
<span>單選父拒絕</span>
<HuiCascader
ref="fixedSingleRef"
:model-value="[0, '']"
:options="options"
clearable
style="width: 240px"
@update:model-value="record('fixedSingle', 'update', $event)"
@clear="record('fixedSingle', 'clear')"
@change="record('fixedSingle', 'change', $event)"
/>
<HuiButton class="cascade-clear-fixed-single-button" @click="fixedSingleRef?.clear()"
>單選請求清除</HuiButton
>
</HuiSpace>
<span class="cascade-clear-fixed-single-status">{{ notices.fixedSingle.join(' → ') }}</span>
<HuiSpace class="cascade-clear-multiple" wrap>
<span>多選父接受</span>
<HuiCascader
ref="multipleRef"
v-model="multiple"
:options="options"
multiple
clearable
style="width: 240px"
@update:model-value="record('multiple', 'update', $event)"
@clear="record('multiple', 'clear')"
@change="record('multiple', 'change', $event)"
/>
<HuiButton class="cascade-clear-multiple-button" @click="multipleRef?.clear()"
>多選清除</HuiButton
>
</HuiSpace>
<span class="cascade-clear-multiple-status"
>模型:{{ JSON.stringify(multiple) }};{{ notices.multiple.join(' → ') }}</span
>
<HuiSpace class="cascade-clear-fixed-multiple" wrap>
<span>多選父拒絕</span>
<HuiCascader
ref="fixedMultipleRef"
:model-value="[[0, '']]"
:options="options"
multiple
clearable
style="width: 240px"
@update:model-value="record('fixedMultiple', 'update', $event)"
@clear="record('fixedMultiple', 'clear')"
@change="record('fixedMultiple', 'change', $event)"
/>
<HuiButton class="cascade-clear-fixed-multiple-button" @click="fixedMultipleRef?.clear()"
>多選請求清除</HuiButton
>
</HuiSpace>
<span class="cascade-clear-fixed-multiple-status">{{ notices.fixedMultiple.join(' → ') }}</span>
<HuiButton class="cascade-clear-reset" @click="reset">恢復示例</HuiButton>
</HuiSpace>
</template>
Props
| 屬性 | 類型 | 預設值 | 說明 |
|---|---|---|---|
| modelValue | string | number | (string | number)[] | (string | number)[][] | null | - | 未傳或僅監聽時自持;傳入即受控(含undefined/null為空),支援 v-model。單選是路徑陣列,多選是路徑陣列的陣列 |
| options | CascaderOption[] | - | 選項資料,必填 |
| multiple | boolean | false | 是否多選 |
| disabled | boolean | false | 是否禁用 |
| clearable | boolean | false | 有值時是否顯示清除按鈕 |
| filterable | boolean | false | 是否可搜尋 |
| placeholder | string | 隨語言(中文:請選擇) | 提示文字 |
| size | 'small' | 'default' | 'large' | 'default' | 尺寸 |
| trigger | 'click' | 'hover' | 'click' | 下一級的展開方式:點擊或滑鼠暫留 |
| checkStrictly | boolean | false | 單選時是否可以選任意一級;多選時父子是否不關聯 |
| showAllLevels | boolean | true | 輸入框和標籤裡是否顯示完整路徑,false 時只顯示最後一級 |
| separator | string | '/' | 路徑裡各級文字之間的分隔符 |
| collapseTags | boolean | true | 多選時折疊超出的標籤 |
| maxCollapseTags | number | 3 | 折疊前顯示的標籤數,collapseTags 為 true 時生效 |
| collapseTagsTooltip | boolean | false | 滑鼠停在 +N 上時是否提示被折疊的選項 |
| debounce | number | 300 | 搜尋防抖時間,單位毫秒。小於等於 0 時不防抖 |
| beforeFilter | (query: string) => boolean | void | Promise<boolean | void> | - | 搜尋前呼叫;undefined 放行,false、throw/reject 攔截並清除目前搜尋;過期結果無效 |
| props | CascaderFieldNames | {} | 自訂選項資料的欄位名 |
| validateEvent | boolean | true | 值變化和收起下拉面板時是否觸發所在表單項的驗證 |
Events
| 事件 | 回呼參數 | 說明 |
|---|---|---|
| update:modelValue | (value: (string | number)[] | (string | number)[][] | null) | 值變化時觸發,v-model 用 |
| change | (value: (string | number)[] | (string | number)[][] | null) | 使用者選擇、勾選、移除標籤或清除時的請求值,父元件可接受或拒絕 |
| clear | - | 點清除按鈕或呼叫clear()時觸發 |
| visibleChange | (visible: boolean) | 下拉面板展開或收起時觸發 |
| expandChange | (path: (string | number)[]) | 展開的路徑變化時觸發,參數是目前展開到的路徑 |
| removeTag | (path: (string | number)[]) | 僅點擊標籤上的叉時觸發;取消勾選透過 change 觀察 |
Slots
| 插槽 | 作用域參數 | 說明 |
|---|---|---|
| empty | - | 沒有選項或搜尋沒有結果時的提示,預設隨語言(中文:暫無資料) |
| node | { node: CascaderNode, checked: boolean } | 替換普通選單和搜尋結果的節點文字;node.rawOption 保留業務資料 |
自訂節點文字
普通選單和搜尋結果使用同一個 node 插槽。路徑欄位為副本;原始業務欄位從 node.rawOption 讀取。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiCascader, HuiSpace } from '@nscode/handy-ui'
import type { CascaderProps } from '@nscode/handy-ui'
const value = ref<CascaderProps['modelValue']>(null)
const options = [
{
value: 'a',
label: '甲區域',
count: 12,
children: [{ value: 'a1', label: '甲一', count: 6 }]
},
{ value: 'b', label: '乙區域', count: 8 }
]
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiCascader v-model="value" :options="options" filterable :debounce="0" style="width: 280px">
<template #node="{ node, checked }"
><span
>{{ node.label }}({{ node.rawOption.count }}){{ checked ? ' ✓' : '' }}</span
></template
>
</HuiCascader>
<span>路徑:{{ JSON.stringify(value) }}</span>
</HuiSpace>
</template>
方法
透過元件的 ref 呼叫。
| 方法 | 參數 | 回傳值 | 說明 |
|---|---|---|---|
| focus | - | void | 讓選擇器獲得焦點;可搜尋並且已展開時聚焦到搜尋框 |
| blur | - | void | 讓選擇器失去焦點 |
| clear | - | void | 請求單選null或多選[];禁用、表單唯讀、卸載後無效,父拒絕保持實際值 |
ref 上還有兩個唯讀屬性:selectedNodes(目前選取項的清單,類型是 CascaderSelectedItem[])和 activePath(目前展開到的路徑)。
類型
import type { CascaderSelectedItem } from '@nscode/handy-ui'
export interface CascaderExpose {
focus: () => void
blur: () => void
clear: () => void
readonly selectedNodes: CascaderSelectedItem[]
readonly activePath: (string | number)[]
}
import type {
CascaderOption,
CascaderFieldNames,
CascaderNode,
CascaderSelectedItem,
CascaderSize,
CascaderTrigger
} from '@nscode/handy-ui'
interface CascaderOption {
value: string | number
label: string
children?: CascaderOption[]
disabled?: boolean
[key: string]: unknown
}
/** props 屬性的結構:資料裡對應的欄位名 */
interface CascaderFieldNames {
value?: string
label?: string
children?: string
disabled?: string
}
/** ref 上 selectedNodes 的每一項 */
interface CascaderSelectedItem {
node: CascaderNode
path: (string | number)[]
pathLabels: string[]
}
interface CascaderNode {
value: string | number
label: string
level: number
path: (string | number)[]
pathLabels: string[]
children?: CascaderNode[]
/** 自己或者任意一級父節點被禁用 */
disabled: boolean
hasChildren: boolean
isLeaf: boolean
rawOption: CascaderOption
}
type CascaderSize = 'small' | 'default' | 'large'
type CascaderTrigger = 'click' | 'hover'