Skip to content

Cascader

cascader

Rule

Basic Example

js
const rule = {
    type: 'cascader',
    title: 'Multi-Level Selection',
    field: 'cascader',
    value: '330100',
    props: {
        options: [
            {
                text: 'Zhejiang Province',
                value: '330000',
                children: [{text: 'Hangzhou City', value: '330100'}],
            },
            {
                text: 'Jiangsu Province',
                value: '320000',
                children: [{text: 'Nanjing City', value: '320100'}],
            },
        ],
        placeholder: 'Select',
    }
}

Props Configuration Examples

Three-Level Linkage

js
const rule = {
    type: 'cascader',
    title: 'Location',
    field: 'address',
    value: '',
    props: {
        title: 'Select Address',
        options: [
            {
                text: 'Zhejiang Province',
                value: '330000',
                children: [
                    {
                        text: 'Hangzhou City',
                        value: '330100',
                        children: [
                            {text: 'Xihu District', value: '330106'},
                            {text: 'Yuhang District', value: '330110'},
                        ]
                    },
                ],
            },
        ],
        placeholder: 'Select area',
    }
}

Custom Field Names

js
const rule = {
    type: 'cascader',
    title: 'Product Category',
    field: 'category',
    value: '',
    props: {
        title: 'Select Category',
        options: [
            {
                label: 'Electronics',
                id: '1',
                items: [
                    {label: 'Mobile Phone', id: '11'},
                    {label: 'Computer', id: '12'},
                ]
            },
        ],
        fieldNames: {
            text: 'label',
            value: 'id',
            children: 'items',
        },
    }
}

Events Examples

Listen to Selection Changes

js
const rule = {
    type: 'cascader',
    title: 'Location',
    field: 'address',
    value: '',
    props: {
        title: 'Select Address',
        options: [
            {
                text: 'Zhejiang Province',
                value: '330000',
                children: [{text: 'Hangzhou City', value: '330100'}],
            },
        ],
        placeholder: 'Select',
    },
    on: {
        change: (result) => {
            console.log('Selection changed:', result);
        },
        finish: (result) => {
            console.log('Selection completed:', result);
        },
        close: () => {
            console.log('Selector closed');
        },
    },
}

Linkage Update After Selection

js
const rule = [
    {
        type: 'cascader',
        title: 'Location',
        field: 'address',
        value: '',
        props: {
            title: 'Select Address',
            options: [
                {
                    text: 'Zhejiang Province',
                    value: '330000',
                    children: [{text: 'Hangzhou City', value: '330100'}],
                },
            ],
        },
        inject: true,
        on: {
            finish: ($inject, result) => {
                // Auto-fill postal code based on selected area
                const zipCodeMap = {
                    '330000': '310000',
                    '330100': '310000',
                };
                const value = result.value;
                if (zipCodeMap[value]) {
                    $inject.api.setValue('zipCode', zipCodeMap[value]);
                }
            },
        },
    },
    {
        type: 'input',
        title: 'Postal Code',
        field: 'zipCode',
        props: {
            disabled: true,
        },
    },
]

Complete configuration items:Vant_Cascader

value :String|Number

Props

ParameterDescriptionTypeDefault Value
v-modelSelected valuestring | number-
titleTop titlestring-
optionsData source for optionsCascaderOption[][]
placeholderPlaceholder text when not selectedstringPlease select
disabledWhether to disable inputbooleanfalse
active-colorHighlight color in selected statestring#1989fa
swipeableWhether to enable left-right swipe gesture to switchbooleantrue
closeableWhether to show close iconbooleantrue
show-headerWhether to show title barbooleantrue
close-iconClose icon name or image link, same as Icon component's name attributestringcross
field-namesCustom fields in options structureCascaderFieldNames{ text: 'text', value: 'value', children: 'children' }

Events

EventDescriptionCallback Parameters
changeTriggered when selected item changes{ value: string | number, selectedOptions: CascaderOption[], tabIndex: number }
finishTriggered when all options are selected{ value: string | number, selectedOptions: CascaderOption[], tabIndex: number }
closeTriggered when close icon is clicked-
click-tabTriggered when tab is clickedtabIndex: number, title: string

FormCreate is an open-source project released under the MIT License. Free for personal and commercial use.