2020-01-19 19:29:30 +08:00
..
2020-01-19 14:34:14 +08:00
2020-01-19 11:57:09 +08:00
2019-12-29 08:35:57 +08:00
2020-01-19 19:29:30 +08:00
2020-01-18 20:14:16 +08:00

Icon

Install

import Vue from 'vue';
import { Icon } from 'vant';

Vue.use(Icon);

Usage

Basic Usage

Use name prop to set icon name or icon URL

<van-icon name="chat-o" />
<van-icon name="https://b.yzcdn.cn/vant/icon-demo-1126.png" />

Show Info

Use dot prop, a small red dot will be displayed in the upper right corner of the icon.

Use info prop, the info will be displayed in the upper right corner of the icon.

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

Icon Color

Use color prop to set icon color

<van-icon name="chat-o" color="#1989fa" />
<van-icon name="chat-o" color="#07c160" />

Icon Size

Use size prop to set icon size

<van-icon name="chat-o" size="40" />
<van-icon name="chat-o" size="3rem" />

Use local font file

Icon uses font file in yzcdn.cn by defaultif you want to use the local font fileplease import the following css file.

import 'vant/lib/icon/local.css';

Add custom iconfont

@font-face {
  font-family: 'my-icon';
  src: url('./my-icon.ttf') format('truetype');
}

.my-icon {
  font-family: 'my-icon';
}

.my-icon-extra::before {
  content: '\e626';
}
<van-icon class-prefix="my-icon" name="extra" />

API

Props

Attribute Description Type Default
name Icon name or URL string ''
dot v2.2.1 Whether to show red dot boolean false
info Content of the badge string | number ''
color Icon color string inherit
size Icon size string | number inherit
class-prefix ClassName prefix string van-icon
tag HTML Tag string i

Events

Event Description Arguments
click Triggered when click icon event: Event