Skip to content

t-dropdown-item

DropdownItem 下拉项

组件介绍

下拉菜单项组件,与t-dropdown-menu组件配合使用,用于承载单个筛选面板的内容,支持自定义选项和插槽。

平台兼容

HarmonyH5AndroidiOS小程序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

属性名类型默认值说明可选值
sizeString"medium"组件尺寸large, medium, small, mini
typeString"primary"组件类型info, primary, error, warning, success
disabledBooleanfalse组件是否禁用true, false
hoverBooleanfalse是否有点击效果true, false
pathString""点击组件后跳转的页面路径-
effectString"normal"组件显示主题normal, dark, light, plain
propString""表单数据对应的字段名-
labelString""标签-
labelKeyString"label"标签对应的数据的字段名-
valueKeyString"value"值对应的字段名-
optionsArray[]选项数据-

Events

事件名说明回调参数
click点击时触发-
touchstart触摸开始时触发触摸事件对象
touchend触摸结束时触发触摸事件对象
touchmove触摸移动时触发触摸事件对象
touchcancel触摸取消时触发触摸事件对象

Slots

插槽名说明
default自定义选项内容插槽,用于自定义下拉面板的内容