Skip to content

CyberCascader 级联选择器

级联选择器用于多层级数据的选择,支持单选和多选模式。

基础用法

vue
<template>
  <cyber-cascader 
    v-model="value"
    :options="options"
    placeholder="请选择"
  />
</template>

<script setup>
import { ref } from 'vue';

const value = ref('');
const options = ref([
  {
    label: '电子产品',
    value: 'electronics',
    children: [
      { label: '手机', value: 'phone' },
      { label: '电脑', value: 'computer' },
    ],
  },
]);
</script>

多选模式

vue
<cyber-cascader 
  v-model="values"
  :options="options"
  multiple
/>

只显示最后一级

默认显示完整路径(如:电子产品 / 手机 / iPhone),设置 show-all-levelsfalse 可只显示最后一级。

vue
<cyber-cascader 
  v-model="value"
  :options="options"
  :show-all-levels="false"
/>

不同主题

vue
<cyber-cascader theme="neon" :options="options" />
<cyber-cascader theme="terminal" :options="options" />
<cyber-cascader theme="matrix" :options="options" />
<cyber-cascader theme="hologram" :options="options" />

API

Props

参数说明类型默认值
modelValue绑定值string | number | (string | number)[]-
options选项数据CascaderOption[][]
placeholder占位文本string'请选择'
noDataText无数据文本string'暂无数据'
disabled是否禁用booleanfalse
clearable是否可清空booleantrue
multiple是否多选booleanfalse
showAllLevels是否显示完整路径booleantrue
size尺寸'large' | 'default' | 'small''default'
theme主题'neon' | 'terminal' | 'matrix' | 'hologram''neon'
labelKey选项标签键名string'label'
valueKey选项值键名string'value'
childrenKey子选项键名string'children'

Events

事件名说明回调参数
update:modelValue绑定值变化时触发(value: ModelValue) => void
change选中值变化时触发(value: ModelValue) => void
focus获得焦点时触发(event: FocusEvent) => void
blur失去焦点时触发(event: FocusEvent) => void
visible-change下拉框出现/隐藏时触发(visible: boolean) => void
clear点击清空按钮时触发() => void

CascaderOption

typescript
interface CascaderOption {
  label?: string;
  value?: string | number;
  disabled?: boolean;
  children?: CascaderOption[];
  [key: string]: any;
}

交互方式

Cascader 组件采用树形展开的交互方式:

  • 点击有子菜单的选项会展开/收起子菜单
  • 子菜单以缩进形式显示在父选项下方
  • 点击叶子节点(没有子菜单的选项)进行选择
  • 支持递归展开多级菜单

这种方式相比面包屑导航更加直观,用户可以同时看到多个层级的选项。

Relcased under the Mit Lincense.