t-dropdown-item
DropdownItem 下拉项
组件介绍
下拉菜单项组件,与t-dropdown-menu组件配合使用,用于承载单个筛选面板的内容,支持自定义选项和插槽。
平台兼容
| Harmony | H5 | Android | iOS | 小程序 | UTS |
|---|---|---|---|---|---|
| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
基础用法
vue
<template>
<t-dropdown-menu :model="formData" @select="handleSelect">
<t-dropdown-item prop="sort" label="排序" :options="sortOptions">
</t-dropdown-item>
<t-dropdown-item prop="category" label="分类" :options="categoryOptions">
</t-dropdown-item>
<t-dropdown-item prop="price" label="价格">
<!-- 自定义选项内容 -->
<t-row v-for="(item, index) in priceOptions" :key="index"
:class="[index < priceOptions.length - 1 ? 'bb-1px,s,#f7f7f7' : '']"
@click="selectPrice(item)">
<t-text :type="formData.price === item.value ? 'primary' : ''">{{ item.label }}</t-text>
<t-icon v-if="formData.price === item.value" name="checkbox-mark" type="primary"></t-icon>
</t-row>
</t-dropdown-item>
</t-dropdown-menu>
</template>
<script setup>
const formData = ref({
sort: 'default',
category: '',
price: ''
});
const sortOptions = ref([
{ value: 'default', label: '默认排序' },
{ value: 'price_asc', label: '价格从低到高' },
{ value: 'price_desc', label: '价格从高到低' },
{ value: 'sales_desc', label: '销量从高到低' }
]);
const categoryOptions = ref([
{ value: '', label: '全部分类' },
{ value: 'electronics', label: '电子产品' },
{ value: 'clothing', label: '服装' },
{ value: 'food', label: '食品' }
]);
const priceOptions = ref([
{ value: '', label: '全部价格' },
{ value: '0-100', label: '0-100元' },
{ value: '100-500', label: '100-500元' },
{ value: '500-1000', label: '500-1000元' },
{ value: '1000+', label: '1000元以上' }
]);
function handleSelect(data) {
console.log('选择结果:', data);
}
function selectPrice(item) {
formData.value.price = item.value;
// 触发父组件的select事件
}
</script>Props
| 属性名 | 类型 | 默认值 | 说明 | 可选值 |
|---|---|---|---|---|
| size | String | "medium" | 组件尺寸 | large, medium, small, mini |
| type | String | "primary" | 组件类型 | info, primary, error, warning, success |
| disabled | Boolean | false | 组件是否禁用 | true, false |
| hover | Boolean | false | 是否有点击效果 | true, false |
| path | String | "" | 点击组件后跳转的页面路径 | - |
| effect | String | "normal" | 组件显示主题 | normal, dark, light, plain |
| prop | String | "" | 表单数据对应的字段名 | - |
| label | String | "" | 标签 | - |
| labelKey | String | "label" | 标签对应的数据的字段名 | - |
| valueKey | String | "value" | 值对应的字段名 | - |
| options | Array | [] | 选项数据 | - |
Events
| 事件名 | 说明 | 回调参数 |
|---|---|---|
| click | 点击时触发 | - |
| touchstart | 触摸开始时触发 | 触摸事件对象 |
| touchend | 触摸结束时触发 | 触摸事件对象 |
| touchmove | 触摸移动时触发 | 触摸事件对象 |
| touchcancel | 触摸取消时触发 | 触摸事件对象 |
Slots
| 插槽名 | 说明 |
|---|---|
| default | 自定义选项内容插槽,用于自定义下拉面板的内容 |