Select (下拉选择)
下拉选择器,支持配置是否可清除、占位符、文本类名、图标类名、遮罩类名、绑定值、选项数据、下拉菜单类名等
支持平台
安卓 | 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>
属性
名称 | 类型 | 默认值 | 说明 | 可选值 |
---|---|---|---|---|
size | String | mini | 组件尺寸 | large(大尺寸), medium(中尺寸), small(小尺寸), mini(迷你) |
type | String | "" | 组件类型 | info(信息), primary(正常), error(错误), warning(警告), success(成功) |
disabled | Boolean | false | 组件是否禁用 | false, true |
stop | Boolean | false | 是否阻止事件冒泡(Tui统一写法处理事件冒泡) | false, true |
hover | Boolean | true | 是否有点击效果 | false, true |
path | String | "" | 点击组件后跳转的页面路径,如果为空则响应点击事件,如果不为空则跳转页面不会响应单击事件。 | - |
mainClass | String | "" | 组件根节点的样式 | - |
nativeClass | String | "" | 组件根节点原生样式 | - |
effect | String | "normal" | 组件显示主题 | normal(正常), dark(深色), light(浅色), plain(镂空) |
leftIcon | String | `` | 左侧图标 | |
rightIconClass | String |
| 右侧图标样式 | |
modelValue | any | `` | 双向绑定的值 | |
rightIcon | String | arrow-down | 右侧图标 | |
closeable | Boolean | true | 是否显示删除按钮 | |
popoverAttrs | any | {} | 下拉选择框的属性配置,t-popover的所有属性 | |
leftIconClass | String | `` | 左侧图标样式 | |
labeBoxlClass | String | `` | 标签盒子的样式 | |
closeableClass | String | `` | 清除按钮的样式 | |
labelClass | String | `` | 选项文字的样式 | |
textClass | String | `` | 请选择文字的样式 |
事件
名称 | 返回参数 | 说明 |
---|---|---|
change | (e:any) | 值化生变化时触发 单选时返回字符,多选时返回字符串数组 |
close | false | 折叠时触发 |
open | true | 展开时触发 |
插槽
名称 | 返回值 | 说明 |
---|---|---|
default | - |