# Icon 图标

### 介绍

基于字体的图标集， 可以通过 Icon 组件使用，也可以在其他组件中通过`icon`属性引用

### 引入

在`index.config.js中引入组件

```json
"usingComponents": {
  "van-icon": "@vant/weapp/icon/index"
}
```

## 代码演示

### 基础用法

`Icon`的`name`属性支持传入图标名称或图片链接

```html
<van-icon name="close" />
<van-icon name="https://xxx/xxx/icon-demo.png" />
```

### 提示信息

设置`dot`属性后，会在图标右上角展示一个小红点。设置`info`属性后，会在图标右上角展示相应的徽标

```html
<van-icon name="chat" dot />
<van-icon name="chat" info="9" />
<van-icon name="chat" info="99+" />
```

### 图标颜色

设置`color`属性来控制图标颜色

```html
<van-icon name="chat" color="red" />
```

### 图标大小

设置`size`属性来控制图标大小

```html
<van-icon name="chat" size="50px" />
```

## 常见问题

### 开发者工具上提示 Faild to load font 是什么情况？

这个是开发者工具本身的问题，可以忽略，具体可以查看[微信小程序文档](https://developers.weixin.qq.com/miniprogram/dev/api/ui/font/wx.loadFontFace.html)注意第 5 条

## API
### 注:属性应用在组件上需要统一使用驼峰式命名，如custom-class应变为
```html
<van-button type="primary" customClass='myClass' size="large">大号按钮</van-button>
```
### 注:事件应用在组件上需要统一使用驼峰式命名，如bind:click/bind:search/bind:before-enter应变为
```html
<van-button type="primary" onClick={()=>this.onClick()}>大号按钮</van-button>
<van-search type="primary" onSearch={()=>this.onSearch()}>大号按钮</van-search>
<van-transition type="primary" onBeforeEnter={()=>this.onBeforeEnter()}>大号按钮</van-transition>
```
### Props

| 参数 | 说明 | 类型 | 默认值 | 版本 |
| --- | --- | --- | --- | --- |
| name | 图标名称或图片链接 | _string_ | - | - |
| dot | 是否显示图标右上角小红点 | _boolean_ | `false` | - |
| info | 图标右上角文字提示 | _string \| number_ | - | - |
| color | 图标颜色 | _string_ | `inherit` | - |
| size | 图标大小，如 `20px`，`2em`，默认单位为`px` | _string \| number_ | `inherit` | - |
| custom-style | 自定义样式 | _string_ | - | - |
| class-prefix | 类名前缀 | _string_ | `van-icon` | - |

### Events

| 事件名     | 说明           | 参数 |
| ---------- | -------------- | ---- |
| bind:click | 点击图标时触发 | -    |

### 外部样式类

| 类名         | 说明         |
| ------------ | ------------ |
| custom-class | 根节点样式类 |
