Skip to content

SelectOption (下拉选择)

下拉选择子级的

支持平台

安卓ios鸿蒙web微信小程序

示例代码

html
<template>
	<t-page main-class="p-30 f">
		<t-card title="提示" main-class="mb-30" size="l" type="e"
			sub-title="要注意层级控制,层级写在组件内部在安卓端不生效,请注意参考官方文档正确使用(https://doc.dcloud.net.cn/uni-app-x/css/z-index.html)"></t-card>
		<t-section title="多选" main-class="mb-30"></t-section>
		<t-row main-class="tdr tdb tdp mb-30">
			<t-text>{{val.join('-')}}</t-text>
		</t-row>
		<t-select type="p" main-class="z-3 ov tvg" :modelValue="val" @change="selectchange">
			<t-select-option v-for="(item,index) in options" :key="index" :label="item.label"
				:value="item.value"></t-select-option>
		</t-select>
		<t-button @click="test" main-class="mtb-30" type="p">双向绑定测试</t-button>
		<t-section title="单选" main-class="mb-30"></t-section>
		<t-select type="s" main-class="z-2 ov tvg" v-model="val1" @change="selectchange1">
			<t-select-option v-for="(item,index) in options" :key="index" :label="item.label"
				:value="item.value"></t-select-option>
		</t-select>
		<t-section title="单选-size" main-class="mtb-30"></t-section>
		<t-select type="s" main-class="z-1 ov tvg" v-model="val1" @change="selectchange1" size="mini">
			<t-select-option v-for="(item,index) in options" :key="index" :label="item.label"
				:value="item.value"></t-select-option>
		</t-select>
	</t-page>
</template>
<script setup>
	const val = ref<string[]>(['选项1', '选项3'])
	const val1 = ref<string>('选项3')
	type SelectOptions = {
		value : string
		label : string
		disabled ?: boolean
	}
	const options = ref<SelectOptions[]>([])
	function test() {
		val.value = ['选项4', '选项5']
	}
	function test1() {
		console.log('测试')
	}
	function selectchange1(e : any) {
		console.log(e)
	}
	function selectchange(e : any) {
		console.log(e)
		val.value = e as string[]
	}
	onReady(() => {
		//模拟接口请求
		setTimeout(() => {
			options.value = [{
				value: '选项1',
				label: '黄金糕'
			}, {
				value: '选项2',
				label: '双皮奶',
				disabled: true
			}, {
				value: '选项3',
				label: '蚵仔煎'
			}, {
				value: '选项4',
				label: '龙须面'
			}, {
				value: '选项5',
				label: '北京烤鸭'
			}, {
				value: '选项11',
				label: '北京烤鸭1'
			}, {
				value: '选项6',
				label: 'A选项6'
			}, {
				value: '选项7',
				label: 'A选项7'
			}, {
				value: '选项8',
				label: 'A选项8'
			}, {
				value: '选项9',
				label: 'A选项9'
			}, {
				value: '选项10',
				label: 'A选项10'
			}] as SelectOptions[]
		}, 300)
	})
</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(镂空)
valueString``选项的值
labelString``选项的标签文本

事件

名称返回参数说明
click(e : UniPointerEvent)-