Skip to content

Cascader 多级联动

规则

js
{
    type:"cascader",
    title:"所在区域",
    field:"address",
    value:['陕西省','西安市','新城区'],
    props:{
        options:[{
            value: 'beijing',
            label: '北京',
            children: [
                {
                    value: 'gugong',
                    label: '故宫'
                },
                {
                    value: 'tiantan',
                    label: '天坛'
                },
                {
                    value: 'wangfujing',
                    label: '王府井'
                }
            ]
        }, {
            value: 'jiangsu',
            label: '江苏',
            children: [
                {
                    value: 'nanjing',
                    label: '南京',
                    children: [
                        {
                            value: 'fuzimiao',
                            label: '夫子庙',
                        }
                    ]
                },
                {
                    value: 'suzhou',
                    label: '苏州',
                    children: [
                        {
                            value: 'zhuozhengyuan',
                            label: '拙政园',
                        },
                        {
                            value: 'shizilin',
                            label: '狮子林',
                        }
                    ]
                }
            ]
        }]
    }
}

参考:Ant-design-vue_Cascader

value :Array

Props

参数说明类型默认值
allowClear是否支持清除booleantrue
autofocus自动获取焦点booleanfalse
bordered是否有边框booleantrue
clearIcon自定义的选择框清空图标slot-
changeOnSelect(单选时生效)当此项为 true 时,点选每级菜单选项值都会发生变化,具体见上面的演示booleanfalse
defaultValue默认的选中项string[] | number[][]
disabled禁用booleanfalse
displayRender选择后展示的渲染函数,可使用 #displayRender="{labels, selectedOptions}"({labels, selectedOptions}) => VNodelabels => labels.join(' / ')
popupClassName自定义浮层类名string-
dropdownStyle自定义浮层样式CSSProperties{}
expandIcon自定义次级菜单展开图标slot-
expandTrigger次级菜单的展开方式clickhover
fieldNames自定义 options 中 label value children 的字段object{ label: 'label', value: 'value', children: 'children' }
getPopupContainer菜单渲染父节点。默认渲染到 body 上,如果你遇到菜单滚动定位问题,试试修改为滚动的区域,并相对其定位。Function(triggerNode)() => document.body
loadData用于动态加载选项,无法与 showSearch 一起使用(selectedOptions) => void-
maxTagCount最多显示多少个 tag,响应式模式会对性能产生损耗number | responsive-
maxTagPlaceholder隐藏 tag 时显示的内容v-slot | function(omittedValues)-
multiple支持多选节点boolean-
notFoundContent当下拉列表为空时显示的内容string | slot'Not Found'
open控制浮层显隐boolean-
options可选项数据源Option[]-
placeholder输入框占位文本string'请选择'
placement浮层预设位置bottomLeftbottomRight
showCheckedStrategy定义选中项回填的方式。Cascader.SHOW_CHILD: 只显示选中的子节点。Cascader.SHOW_PARENT: 只显示父节点(当父节点下所有子节点都选中时)。Cascader.SHOW_PARENTCascader.SHOW_CHILD
removeIcon自定义的多选框清除图标slot-
searchValue设置搜索的值,需要与 showSearch 配合使用string-
showSearch在选择框中显示搜索框boolean | objectfalse
status设置校验状态'error' | 'warning'-
size输入框大小largedefault
suffixIcon自定义的选择框后缀图标string | VNode | slot-
tagRender自定义 tag 内容,多选时生效slot-

showSearch 为对象时,其中的字段:

参数说明类型默认值
filter接收 inputValue path 两个参数,当 path 符合筛选条件时,应返回 true,反之则返回 false。function(inputValue, path): boolean
limit搜索结果展示数量number | false50
matchInputWidth搜索结果列表是否与输入框同宽boolean
render用于渲染 filter 后的选项,可使用 #showSearchRender="{inputValue, path}"function({inputValue, path}): VNode
sort用于排序 filter 后的选项function(a, b, inputValue)

Events

事件名称说明回调参数
change选择完成后的回调(value, selectedOptions) => void
dropdownVisibleChange显示/隐藏浮层的回调(value) => void
search监听搜索,返回输入的值(value) => void

Option

ts
interface Option {
  value: string | number;
  label?: any;
  disabled?: boolean;
  children?: Option[];
  // 标记是否为叶子节点,设置了 `loadData` 时有效
  // 设为 `false` 时会强制标记为父节点,即使当前节点没有 children,也会显示展开图标
  isLeaf?: boolean;
}

FormCreate 是一个开源项目,基于 MIT 许可证发布,欢迎个人和企业用户免费使用