2018-05-16 20:57:22 +08:00
---
title: Icon
2019-01-29 16:31:24 +08:00
preview: https://didi.github.io/mand-mobile/examples/#/icon
2018-05-16 20:57:22 +08:00
---
2019-03-21 23:07:22 +08:00
IconFont、SVG Icons
2018-05-16 20:57:22 +08:00
### Import
```javascript
import { Icon } from 'mand-mobile'
Vue.component(Icon.name, Icon)
```
2019-05-06 18:01:40 +08:00
### Instruction
Custom svg icons and import local font file, please refer to < a href = "javascript:jumpAnchor('Appendix')" > Appendix< / a > .
2018-10-10 15:03:30 +08:00
### Code Examples
<!-- DEMO -->
### API
#### Icon Props
|Props | Description | Type | Default | Note |
|----|-----|------|------|------|
|name|icon name|String|-|-|
2024-04-28 11:53:33 +08:00
|size|icon size|String|`md`|`xxs`< sup class = "version-after" > 2.7.1+</ sup > , `xs` , `sm` , `md` , `lg` |
2018-10-10 15:03:30 +08:00
|color|icon color|String|`currentColor`|this color value is set as the value of `fill` on the `svg` icon|
2023-02-01 20:56:03 +08:00
|svg|use svg icon|Boolean|`false` `true` < sup class = "version-after" > 2.6.1+</ sup > |Due to the inability to load web fonts in Apple [Lockdown Mode ](https://support.apple.com/en-us/HT212650 ), the SVG icon is used by default since 2.6.1, and iconfont is used when set to `false` |
2018-05-16 20:57:22 +08:00
2018-10-10 15:03:30 +08:00
### Appendix
2018-05-16 20:57:22 +08:00
2019-05-06 18:01:40 +08:00
#### Custom svg icons
2018-11-15 21:18:03 +08:00
As for custom svg icons, you need to use < a href = "https://github.com/kisenka/svg-sprite-loader" target = "_blank" > svg-sprite-loader< / a > , svg file name is the icon name.
2018-05-16 20:57:22 +08:00
1. Install Dependencies
```shell
npm install svg-sprite-loader --save-dev
```
2. Webpack Configuration
```javascript
const path = require('path')
module.exports = {
module: {
loaders: [
{
test: /\.svg$/i,
loader: 'svg-sprite-loader',
include: [
// All svg icons in a path are handled by svg-sprite-loader plugin
path.resolve(__dirname, 'src/my-project-svg-folder')
],
}
]
}
}
```
3. Import Icons
```vue
< template >
< div >
2019-02-14 14:42:54 +08:00
< md-icon name = "hello" svg > < / md-icon >
< md-icon name = "world" svg > < / md-icon >
2018-05-16 20:57:22 +08:00
< / div >
< / template >
< script >
import 'src/my-project-svg-folder/hello.svg'
import 'src/my-project-svg-folder/world.svg'
import { Icon } from 'mand-mobile'
export default {
name: 'icon-demo',
2018-08-08 14:13:26 +08:00
components: {
2018-05-16 20:57:22 +08:00
[Icon.name]: Icon
}
}
< / script >
2019-05-06 18:01:40 +08:00
```
#### Importing local font files
> Note: webpack [url-loader](https://github.com/webpack-contrib/url-loader) configuration needs to include mand-mobile
2023-02-01 20:56:03 +08:00
* Reset icon fonts in css
2019-05-06 18:01:40 +08:00
```css
@font -face{
font-family: Mand-Mobile-Icon;
font-style: normal;
font-weight: 400;
src: url(~mand-mobile/components/icon/iconfont.woff) format("woff"),url(~mand-mobile/components/icon/iconfont.woff) format("truetype")
}
2023-02-01 20:56:03 +08:00
```
2019-05-06 18:01:40 +08:00
* Reset stylus variable when customizing theme
```
icon-font-family = url("./iconfont.woff") format("woff"), url("./iconfont.ttf") format("truetype")
2023-02-01 20:56:03 +08:00
```