Skip to content

Cascader (级联选择器)

级联选择器组件,多级菜单灵活选择,支持动态数据加载/支持禁用选项(内容区可滚动需要设置 scroll的高度,不设置高度会自适应)

支持平台

安卓ios鸿蒙web微信小程序

示例代码

html
<template>
	<t-page>
		<t-card main-class='mltr-30' title="Cascader 级联选择器"
			sub-title='级联选择器组件,多级菜单灵活选择,支持动态数据加载/支持禁用选项(内容区可滚动需要设置 scroll的高度,不设置高度会自适应)'></t-card>
		<introduction title='基础功能'>
			<t-text main-class="tdb tdr tdp mb-30">value={{value1.join('-')}}</t-text>
			<t-cascader v-model="value1" type="s" :option="list"></t-cascader>
			<t-button type="p" @click="value1=['zhinan', 'shejiyuanze', 'xiaolv']">双向绑定测试</t-button>
		</introduction>
		<introduction title='默认值'>
			<t-text main-class="tdb tdr tdp mb-30">value={{value.join('-')}}</t-text>
			<t-cascader v-model="value" type="p" :option="list"></t-cascader>
		</introduction>
	</t-page>
</template>

<script setup>
	const value1 = ref<string[]>(['zhinan', 'shejiyuanze', 'fankui'])
	const value = ref<string[]>(['zhinan', 'shejiyuanze', 'fankui'])
	const list = ref<UTSJSONObject[]>([
		{
			"value": "zhinan",
			"label": "指南",
			"children": [
				{
					"value": "shejiyuanze",
					"label": "设计原则",
					"children": [
						{
							"value": "yizhi",
							"label": "一致",
							"disabled": true
						},
						{
							"value": "fankui",
							"label": "反馈"
						},
						{
							"value": "xiaolv",
							"label": "效率"
						},
						{
							"value": "kekong",
							"label": "可控"
						}
					]
				},
				{
					"value": "daohang",
					"label": "导航",
					"children": [
						{
							"value": "cexiangdaohang",
							"label": "侧向导航"
						},
						{
							"value": "dingbudaohang",
							"label": "顶部导航"
						}
					]
				}
			]
		},
		{
			"value": "zujian",
			"label": "组件",
			"children": [
				{
					"value": "basic",
					"label": "Basic",
					"children": [
						{
							"value": "layout",
							"label": "Layout 布局"
						},
						{
							"value": "color",
							"label": "Color 色彩"
						},
						{
							"value": "typography",
							"label": "Typography 字体"
						},
						{
							"value": "icon",
							"label": "Icon 图标"
						},
						{
							"value": "button",
							"label": "Button 按钮"
						}
					]
				},
				{
					"value": "form",
					"label": "Form",
					"children": [
						{
							"value": "radio",
							"label": "Radio 单选框"
						},
						{
							"value": "checkbox",
							"label": "Checkbox 多选框"
						},
						{
							"value": "input",
							"label": "Input 输入框"
						},
						{
							"value": "input-number",
							"label": "InputNumber 计数器"
						},
						{
							"value": "select",
							"label": "Select 选择器"
						},
						{
							"value": "cascader",
							"label": "Cascader 级联选择器"
						},
						{
							"value": "switch",
							"label": "Switch 开关"
						},
						{
							"value": "slider",
							"label": "Slider 滑块"
						},
						{
							"value": "time-picker",
							"label": "TimePicker 时间选择器"
						},
						{
							"value": "date-picker",
							"label": "DatePicker 日期选择器"
						},
						{
							"value": "datetime-picker",
							"label": "DateTimePicker 日期时间选择器"
						},
						{
							"value": "upload",
							"label": "Upload 上传"
						},
						{
							"value": "rate",
							"label": "Rate 评分"
						},
						{
							"value": "form",
							"label": "Form 表单"
						}
					]
				},
				{
					"value": "data",
					"label": "Data",
					"children": [
						{
							"value": "table",
							"label": "Table 表格"
						},
						{
							"value": "tag",
							"label": "Tag 标签"
						},
						{
							"value": "progress",
							"label": "Progress 进度条"
						},
						{
							"value": "tree",
							"label": "Tree 树形控件"
						},
						{
							"value": "pagination",
							"label": "Pagination 分页"
						},
						{
							"value": "badge",
							"label": "Badge 标记"
						}
					]
				},
				{
					"value": "notice",
					"label": "Notice",
					"children": [
						{
							"value": "alert",
							"label": "Alert 警告"
						},
						{
							"value": "loading",
							"label": "Loading 加载"
						},
						{
							"value": "message",
							"label": "Message 消息提示"
						},
						{
							"value": "message-box",
							"label": "MessageBox 弹框"
						},
						{
							"value": "notification",
							"label": "Notification 通知"
						}
					]
				},
				{
					"value": "navigation",
					"label": "Navigation",
					"children": [
						{
							"value": "menu",
							"label": "NavMenu 导航菜单"
						},
						{
							"value": "tabs",
							"label": "Tabs 标签页"
						},
						{
							"value": "breadcrumb",
							"label": "Breadcrumb 面包屑"
						},
						{
							"value": "dropdown",
							"label": "Dropdown 下拉菜单"
						},
						{
							"value": "steps",
							"label": "Steps 步骤条"
						}
					]
				},
				{
					"value": "others",
					"label": "Others",
					"children": [
						{
							"value": "dialog",
							"label": "Dialog 对话框"
						},
						{
							"value": "tooltip",
							"label": "Tooltip 文字提示"
						},
						{
							"value": "popover",
							"label": "Popover 弹出框"
						},
						{
							"value": "card",
							"label": "Card 卡片"
						},
						{
							"value": "carousel",
							"label": "Carousel 走马灯"
						},
						{
							"value": "collapse",
							"label": "Collapse 折叠面板"
						}
					]
				}
			]
		},
		{
			"value": "ziyuan",
			"label": "资源",
			"children": [
				{
					"value": "axure",
					"label": "Axure Components"
				},
				{
					"value": "sketch",
					"label": "Sketch Templates"
				},
				{
					"value": "jiaohu",
					"label": "组件交互文档"
				}
			]
		}
	])
</script>

属性

名称类型默认值说明可选值
sizeStringmini组件尺寸large(大尺寸), medium(中尺寸), small(小尺寸), mini(迷你)
typeString""组件类型info(信息), primary(正常), error(错误), warning(警告), success(成功)
disabledBooleanfalse组件是否禁用false, true
stopBooleanfalse是否阻止事件冒泡(Tui统一写法处理事件冒泡)false, true
hoverBooleantrue是否有点击效果false, true
pathString""点击组件后跳转的页面路径,如果为空则响应点击事件,如果不为空则跳转页面不会响应单击事件。-
mainClassString""组件根节点的样式-
nativeClassString""组件根节点原生样式-
effectString"normal"组件显示主题normal(正常), dark(深色), light(浅色), plain(镂空)
modelValueany``组件的值
optionUTSJSONObject[][]选项数据,用于配置级联选择的数据源
scrollClassString``滚动容器的额外类名,用于自定义滚动容器的样式

事件

名称返回参数说明
change--
update:modelValue--

方法

名称参数返回值说明
reset--
getValue--
onbase--
onmenuselect--
onselect--
ischild--
init--