Cascader
If the options have a clear hierarchical structure, Cascader can be used to view and select them.
Basic usage
There are two ways to expand child option items.
Disabled option
Disable an option by setting a disabled
field in the option object.
Clearable
Set clearable
attribute for el-cascader
and a clear icon will appear when selected and hovered
Display only the last level
The input can display only the last level instead of all levels.
Multiple Selection
Add :props="props"
in tag and set data props = { multiple: true }
to use multiple selection.
Do:
<template>
<el-cascader :props="props" />
</template>
<script lang="ts">
export default {
setup() {
return {
props: {
// props.
multiple: true,
},
}
},
}
</script>
Don't do:
<template>
<!-- Object literal binging here is invalid syntax for cascader -->
<el-cascader :props="{ multiple: true }" />
</template>
Select any level of options
In single selection, only the leaf nodes can be checked, and in multiple selection, check parent nodes will lead to leaf nodes be checked eventually. When enable this feature, it can make parent and child nodes unlinked and you can select any level of options.
Dynamic loading
Dynamic load its child nodes when checked a node.
Filterable
Search and select options with a keyword.
Custom option content
You can customize the content of cascader node.
Cascader panel
CascaderPanel
is the core component of Cascader
which has various of features such as single selection, multiple selection, dynamic loading and so on.
Cascader Attributes
Attribute | Description | Type | Accepted Values | Default |
---|---|---|---|---|
model-value / v-model | binding value | - | — | — |
options | data of the options,the key of value and label can be customize by Props . | array | — | — |
props | configuration options, see the following table. | object | — | — |
size | size of input | string | large / default /small | — |
placeholder | placeholder of input | string | — | Select |
disabled | whether Cascader is disabled | boolean | — | false |
clearable | whether selected value can be cleared | boolean | — | false |
show-all-levels | whether to display all levels of the selected value in the input | boolean | — | true |
collapse-tags | whether to collapse tags in multiple selection mode | boolean | - | false |
separator | option label separator | string | — | ' / ' |
filterable | whether the options can be searched | boolean | — | — |
filter-method | customize search logic, the first parameter is node , the second is keyword , and need return a boolean value indicating whether it hits. | function(node, keyword) | - | - |
debounce | debounce delay when typing filter keyword, in milliseconds | number | — | 300 |
before-filter | hook function before filtering with the value to be filtered as its parameter. If false is returned or a Promise is returned and then is rejected, filtering will be aborted | function(value) | — | — |
popper-class | custom class name for Cascader's dropdown | string | — | — |
teleported | whether cascader popup is teleported | boolean | true / false | true |
popper-append-to-body(deprecated) | whether to append the popper menu to body. If the positioning of the popper is wrong, you can try to set this prop to false | boolean | - | true |
Cascader Events
Event Name | Description | Parameters |
---|---|---|
change | triggers when the binding value changes | value |
expand-change | triggers when expand option changes | an array of the expanding node's parent nodes |
blur | triggers when Cascader blurs | (event: Event) |
focus | triggers when Cascader focuses | (event: Event) |
visible-change | triggers when the dropdown appears/disappears | true when it appears, and false otherwise |
remove-tag | triggers when remove tag in multiple selection mode | the value of the tag which is removed |
Cascader Methods
Method Name | Description | Parameters |
---|---|---|
getCheckedNodes | get an array of currently selected node | (leafOnly) whether only return the leaf checked nodes, default is false |
Cascader Slots
Name | Description |
---|---|
- | the custom content of cascader node, the parameter is { node, data }, which are current Node object and node data respectively. |
empty | content when there is no matched options. |
CascaderPanel Attributes
Attribute | Description | Type | Accepted Values | Default |
---|---|---|---|---|
model-value / v-model | binding value | - | — | — |
options | data of the options,the key of value and label can be customize by Props . | array | — | — |
props | configuration options, see the following table. | object | — | — |
CascaderPanel Events
Event Name | Description | Parameters |
---|---|---|
change | triggers when the binding value changes | value |
expand-change | triggers when expand option changes | an array of the expanding node's parent nodes |
CascaderPanel Methods
Method Name | Description | Parameters |
---|---|---|
getCheckedNodes | get an array of currently selected node | (leafOnly) whether only return the leaf checked nodes, default is false |
clearCheckedNodes | clear checked nodes | - |
CascaderPanel Slots
Name | Description |
---|---|
- | the custom content of cascader node, the parameter is { node, data }, which are current Node object and node data respectively. |
Props
Attribute | Description | Type | Accepted Values | Default |
---|---|---|---|---|
expandTrigger | trigger mode of expanding options | string | click / hover | 'click' |
multiple | whether multiple selection is enabled | boolean | - | false |
checkStrictly | whether checked state of a node not affects its parent and child nodes | boolean | - | false |
emitPath | when checked nodes change, whether to emit an array of node's path, if false, only emit the value of node. | boolean | - | true |
lazy | whether to dynamic load child nodes, use with lazyload attribute | boolean | - | false |
lazyLoad | method for loading child nodes data, only works when lazy is true | function(node, resolve) | - | - |
value | specify which key of node object is used as the node's value | string | — | 'value' |
label | specify which key of node object is used as the node's label | string | — | 'label' |
children | specify which key of node object is used as the node's children | string | — | 'children' |
disabled | specify which key of node object is used as the node's disabled | string | — | 'disabled' |
leaf | specify which key of node object is used as the node's leaf field | string | — | 'leaf' |