# t-select-option
SelectOption 选择项
t-select-option 组件介绍
t-select-option 是下拉选择的子级组件,用于定义下拉菜单中的选项,必须配合 t-select 使用。
t-select-option 平台兼容
| Harmony | H5 | Android | iOS | 小程序 | UTS |
|---|---|---|---|---|---|
| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
t-select-option 基础用法
基础用法参考 demo/select/select.uvue,作为 t-select 的子组件使用。
vue
<template>
<t-page class="p-15 f ov">
<t-card title="提示"
class="mb-15"
type="error"
sub-title="要注意层级控制,层级写在组件内部在安卓端不生效,请注意参考官方文档正确使用(https://doc.dcloud.net.cn/uni-app-x/css/z-index.html)"></t-card>
<t-section title="多选"
class="mb-15"></t-section>
<view :class="[`trm tpm tvg mb-15`]">
<t-text>{{val.join('-')}}</t-text>
</view>
<t-select :class="`z-1000 ov`"
v-model="val"
size="large"
@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 type="primary"
class="mt-15"
@click="test">双向绑定测试</t-button>
<t-section title="单选"
class="mb-15"></t-section>
<view :class="[`trm tpm tvg mb-15`]">
<t-text>{{val1}}</t-text>
</view>
<t-select :class="`z-3 ov`"
v-model="val1"
size="large"
@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-button type="primary"
class="mt-15"
@click="test1">双向绑定测试</t-button>
<view class="h-250"></view>
<tui-theme-switch></tui-theme-switch>
</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() {
val1.value = '选项4'
}
function selectchange1(e : any) {
console.log(e)
}
function selectchange(e : any) {
console.log(e)
}
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>t-select-option Props
| 属性名 | 说明 | 类型 | 默认值 |
|---|---|---|---|
value | 选项的值 | string | '' |
label | 选项的标签文本 | string | '' |
path | 点击组件后跳转的页面路径 | string | '' |
hover | 是否启用点击效果 | boolean | false |
type | 组件主题类型 | string | '' |
disabled | 是否禁用 | boolean | false |
effect | 组件显示主题 | string | '' |
size | 组件尺寸 | string | 'medium' |
t-select-option Events
| 事件名 | 说明 | 回调参数 |
|---|---|---|
click | 点击时触发 | - |