---
title: "Icon"
description: "Used to display an icon."
url: https://weme-ui.github.io/slim/components/icon.md
---
# Icon

图标。包了 `@iconify/vue`。优先用 `name`，`icon` 也能当别名。

## Installation

```bash
pnpm dlx @weme-ui/weme-ui add icon
```

## Usage

```vue
<script lang="ts" setup>
import Icon from '../icon.vue'

const icons = [
  'ri:anthropic-line',
  'ri:wechat-2-line',
  'ri:instagram-line',
  'ri:facebook-line',
  'ri:twitter-line',
  'ri:linkedin-line',
  'ri:youtube-line',
  'ri:tiktok-line',
  'ri:twitch-line',
  'ri:discord-line',
]
</script>

<template>
  <div class="flex flex-wrap gap-4 items-center justify-center">
    <Icon v-for="icon in icons" :key="icon" :name="icon" />
  </div>
</template>
```

## Props

| 属性         | 说明                                      | 类型                                 | 默认值 |
| ------------ | ----------------------------------------- | ------------------------------------ | ------ |
| `name`       | 图标名称或 Iconify 图标数据（必填）       | `IconifyIcon \| string`              | —      |
| `icon`       | `name` 的别名；同时传入时以 `icon` 为准   | `IconifyIcon \| string`              | —      |
| `class`      | 根节点额外 class                          | `any`                                | —      |
| `mode`       | 渲染模式（透传 `@iconify/vue`）           | `'style' \| 'bg' \| 'mask' \| 'svg'` | —      |
| `color`      | 图标颜色（透传）                          | `string`                             | —      |
| `width`      | 宽度（透传）                              | `string \| number \| null`           | —      |
| `height`     | 高度（透传）                              | `string \| number \| null`           | —      |
| `flip`       | 翻转（透传）                              | `string`                             | —      |
| `rotate`     | 旋转（透传）                              | `string \| number`                   | —      |
| `inline`     | 是否按 inline 对齐（透传）                | `boolean`                            | —      |
| `ariaHidden` | 是否对辅助技术隐藏（透传 `@iconify/vue`） | `boolean \| string`                  | —      |

没列出来的属性一样从 `@iconify/vue` 透传过来（`name` 替掉了必填的 `icon`）。

## Accessibility

基于 `@iconify/vue`。装饰用的可以 `ariaHidden` 藏起来。图标自己有含义时别藏，旁边得有字。

## Examples

### Sizes

```vue
<script lang="ts" setup>
import Icon from '../icon.vue'
</script>

<template>
  <div class="flex flex-wrap gap-3 items-center">
    <Icon name="ri:wechat-2-fill" :width="16" :height="16" />
    <Icon name="ri:wechat-2-fill" :width="24" :height="24" />
    <Icon name="ri:wechat-2-fill" :width="32" :height="32" />
  </div>
</template>
```

### Color

```vue
<script lang="ts" setup>
import Icon from '../icon.vue'
</script>

<template>
  <div class="text-gray-100 flex flex-wrap gap-3 items-center">
    <Icon name="ri:wechat-2-fill" color="currentColor" :width="24" :height="24" />
    <Icon name="ri:wechat-2-fill" color="#4CBBA5" :width="24" :height="24" />
    <Icon name="ri:wechat-2-fill" color="#E5484D" :width="24" :height="24" />
  </div>
</template>
```