# 19. TagEllipsis 关键字转 tag 标签
URL: /%E6%96%87%E6%A1%A3/04.%E5%BC%80%E5%8F%91%E6%96%87%E6%A1%A3/01.%20%E5%89%8D%E7%AB%AF%E5%BC%80%E5%8F%91/03.%20%E7%BB%84%E4%BB%B6%E5%BA%93%E6%96%87%E6%A1%A3/08.%20%E4%B8%9A%E5%8A%A1%E7%BB%84%E4%BB%B6/19.%20TagEllipsis%20%E5%85%B3%E9%94%AE%E5%AD%97%E8%BD%AC%20tag%E6%A0%87%E7%AD%BE


# 19. TagEllipsis 关键字转 tag 标签

## 功能说明

TagEllipsis 组件用于将关键字或字符串数组转换为 Tag 标签展示，支持自动省略和悬浮展开功能。当标签数量超过指定限制时，会自动折叠显示省略号，鼠标悬停可查看完整列表。

## 引入方式

```vue
<script setup>
import TagEllipsis from '@/components/Common/TagEllipsis/TagEllipsis.vue';
</script>

<template>
  <TagEllipsis :list="tagList" :limit="2" />
</template>
```

## Props 属性

| 属性 | 说明 | 类型 | 默认值 |
|------|------|------|--------|
| list | 需要转成标签的值，支持数组 `['1','2']` 或对象数组 `[{name: '标签1'}]` 或逗号分隔字符串 `'1,2'` | `Array \| String` | `[]` |
| limit | 限制显示多少个元素后使用省略号 | `String \| Number` | `2` |
| defaultProps | list 为对象数组时，用于显示文字的字段名 | `String` | `'name'` |
| emptyText | 空数据时显示的文本内容，设为 `false` 则不显示 | `Boolean \| String` | - |

## Events 事件

| 事件名 | 说明 | 回调参数 |
|--------|------|----------|
| - | 当前组件无自定义事件 | - |

## 使用示例

### 基础用法 - 字符串数组

```vue
<template>
  <TagEllipsis :list="['标签1', '标签2', '标签3']" :limit="2" />
</template>
```

### 基础用法 - 逗号分隔字符串

```vue
<template>
  <TagEllipsis :list="'标签1,标签2,标签3'" :limit="2" />
</template>
```

### 对象数组 - 自定义字段

```vue
<template>
  <TagEllipsis 
    :list="[{ name: '红色', color: 'red' }, { name: '蓝色', color: 'blue' }]" 
    :defaultProps="'name'" 
    :limit="1" 
  />
</template>
```

### 自定义空状态

```vue
<template>
  <TagEllipsis :list="[]" emptyText="暂无标签" />
  <TagEllipsis :list="[]" :emptyText="false" />
</template>
```

### 配合 a-tag 属性使用

```vue
<template>
  <!-- 所有 attrs 会透传给 a-tag 组件 -->
  <TagEllipsis 
    :list="tagList" 
    color="blue" 
    :limit="2"
  />
</template>
```

## 源码路径

```
Widiazine-New-Frontend/src/components/Common/TagEllipsis/
├── TagEllipsis.vue    # 主组件
```

## 注意事项

1. `defaultProps` 参数仅在 `list` 为对象数组时生效
2. 当使用对象数组时，确保每个对象都有 `defaultProps` 指定的字段
3. 组件会自动过滤空值（空字符串或字段不存在的对象）
4. `limit` 属性控制显示的标签数量，超出部分在 Popover 中展示
