Skip to content

Cascader

Used for hierarchical selection of tree-structured data, supporting both static data and asynchronous loading modes.

Tip

For province-city-district scenarios, you can directly use useCascaderAreaData from @vant/area-data as the data source.

Component Type

Basic Usage

html
<wd-cascader v-model="value" v-model:visible="show" :options="options" @confirm="handleConfirm" />

Initial Options

html
<wd-cascader v-model="value" v-model:visible="show" :options="options" @confirm="handleConfirm" />

Custom Fields

html
<wd-cascader
  v-model="value"
  v-model:visible="show"
  :options="customOptions"
  value-key="id"
  text-key="name"
  children-key="items"
  @confirm="handleConfirm"
/>

Component State

Disabled Options

html
<wd-cascader v-model="value" v-model:visible="show" :options="optionsWithDisabled" @confirm="handleConfirm" />

Option Tips

html
<wd-cascader v-model="value" v-model:visible="show" :options="optionsWithTip" @confirm="handleConfirm" />

Before Confirm Validation

before-confirm supports returning boolean or Promise<boolean>.

html
<wd-cascader
  v-model="value"
  v-model:visible="show"
  :options="options"
  :before-confirm="beforeConfirm"
  @confirm="handleConfirm"
/>
ts
const beforeConfirm = async (value, selectedOptions) => {
  if (String(value) === '120000') return false
  return true
}

Component Style

Display Formatting

ts
const handleConfirm = ({ selectedOptions }) => {
  displayValue.value = `${selectedOptions[selectedOptions.length - 2].text}-${selectedOptions[selectedOptions.length - 1].text}`
}

Set Title

html
<wd-cascader v-model="value" v-model:visible="show" title="Select Address" :options="options" @confirm="handleConfirm" />

Special Style

Asynchronous Loading

After passing lazy-load, it enters asynchronous mode: when option = null, it loads root nodes; resolve([]) indicates the current node is a leaf node.

html
<wd-cascader v-model="value" v-model:visible="show" :lazy-load="lazyLoad" @confirm="handleConfirm" />
ts
const lazyLoad = (option, tabIndex, resolve) => {
  fetchChildren(option ? String(option.value) : null).then(resolve)
}

Asynchronous Loading (No Initial Value)

html
<wd-cascader v-model="value" v-model:visible="show" :lazy-load="lazyLoad" @confirm="handleConfirm" />

Any Level Selectable

After enabling check-strictly, clicking a node only updates the current path, and submission is done through the confirm button in the top right corner.

html
<wd-cascader v-model="value" v-model:visible="show" :options="options" check-strictly @confirm="handleConfirm" />

Attributes

ParameterDescriptionTypeDefault Value
v-modelSelected item. Static mode is leaf node value; asynchronous mode can pass path array for displaystring | number | (string | number)[]-
visible / v-model:visibleWhether to show popupbooleanfalse
optionsHierarchical option data (tree structure)CascaderOption[][]
titlePopup titlestring-
before-confirmValidation function before confirm, parameters are (value, selectedOptions), returns boolean or Promise<boolean>CascaderBeforeConfirm-
check-strictlyWhether to enable any level selectablebooleanfalse
confirm-textConfirm button text in strict modestring''
value-keyOption value field namestringvalue
text-keyOption text field namestringtext
children-keyChild node field namestringchildren
tip-keyTip text field namestringtip
is-leaf-keyLeaf node identifier field name, when value is true, clicking confirmsstringisLeaf
lazy-loadAsynchronous loading callback, parameters are (option, tabIndex, resolve)CascaderLazyLoad-
close-on-click-modalWhether to close when clicking maskbooleantrue
z-indexPopup z-indexnumber15
safe-area-inset-bottomWhether popup panel sets bottom safe distance (iPhone X type devices)booleantrue
line-widthBottom line width, supports number or string with unitnumber | string-
line-heightBottom line height, supports number or string with unitnumber | string-
line-themeBottom line position style, supports normal / text / underline / dotstringnormal
root-portalWhether to render outside document flow (H5: teleport, App: renderjs, Mini Program: root-portal)booleanfalse
custom-classRoot node custom class namestring''
custom-styleRoot node custom stylestring''

CascaderOption Data Structure

KeyDescriptionType
valueOption valuestring | number
textOption textstring
childrenChild optionsCascaderOption[]
disabledWhether disabledboolean
tipTip textstring
isLeafWhether it is a leaf node (asynchronous mode)boolean

Events

Event NameDescriptionParameters
confirmTriggered when confirming selectionStatic mode: { value, selectedOptions }, value is leaf value; Asynchronous mode: { value, selectedOptions }, value is path array
closeTriggered when popup closes-

Methods

Method NameDescriptionParameters
openOpen cascader popup-
closeClose cascader popup-

主题定制

CSS 变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 全局配置

名称默认值描述
--wot-cascader-bg$filled-oppo级联选择器弹层背景色
--wot-cascader-list-heightcalc(336 * #{$n-1})选项列表高度
--wot-cascader-list-item-color$text-main选项文字颜色
--wot-cascader-list-item-opacity-disabled$opacity-disabled选项禁用态透明度
--wot-cascader-list-item-font-size$typography-body-size-extra-large选项文字字号
--wot-cascader-list-item-line-height$typography-body-line--height-size-extra-large选项文字行高
--wot-cascader-list-item-padding$padding-extra-loose $padding-loose选项内边距
--wot-cascader-list-item-color-checked$primary-6选项选中态文字颜色
--wot-cascader-list-item-font-weight-checked$font-weight-medium选项选中态文字字重
--wot-cascader-list-tip-color$text-secondary选项提示文字颜色
--wot-cascader-list-tip-font-size$typography-label-size-main选项提示文字字号
--wot-cascader-list-tip-line-height$typography-label-line--height-size-main选项提示文字行高
--wot-cascader-list-tip-margin-top$spacing-ultra-tight选项提示顶部外边距
--wot-cascader-list-checked-icon-size$n-20选中图标尺寸
--wot-cascader-list-checked-icon-spacing$spacing-tight选中图标与文字间距
--wot-cascader-action-right$spacing-loose关闭图标右侧偏移
--wot-cascader-confirm-color$primary-6checkStrictly模式确认按钮颜色
--wot-cascader-confirm-opacity-disabled$opacity-disabledcheckStrictly模式确认按钮禁用透明度
--wot-cascader-confirm-font-size$typography-body-size-largecheckStrictly模式确认按钮字号
--wot-cascader-confirm-line-height$typography-body-line--height-size-largecheckStrictly模式确认按钮行高
--wot-cascader-confirm-font-weight$font-weight-regularcheckStrictly模式确认按钮字重
--wot-cascader-loading-opacity$opacity-disabledloading 状态下选项区透明度
--wot-cascader-loading-icon-size$n-48loading 图标尺寸

Source Code

Documentation
Component

Released under the MIT License.

Released under the MIT License.