• 引入
  • 使用指南
  • 代码演示
    • 字体图标
    • svg图标
    • 大小
    • 颜色
  • API
    • Icon Props
  • 附录
    • 自定义svg图标
    • 引入本地字体文件

    Icon 图标

    Scan me!

    IconFont、SVG 图标

    引入

    1. import { Icon } from 'mand-mobile'
    2. Vue.component(Icon.name, Icon)

    使用指南

    自定义svg图标和引入本地字体文件,请参考附录)。

    代码演示

    字体图标

    Icon 图标 - 图2

    1. <template>
    2. <div class="md-example-child md-example-child-icon md-example-child-icon-0">
    3. <div
    4. class="md-example-item"
    5. v-for="icon in iconList"
    6. :key="icon"
    7. >
    8. <md-icon
    9. :name="icon.split('/')[0]"
    10. size="lg"
    11. ></md-icon>
    12. <p>{{ icon }}</p>
    13. </div>
    14. </div>
    15. </template>
    16. <script>
    17. import {Icon} from 'mand-mobile'
    18. export default {
    19. name: 'icon-demo',
    20. components: {
    21. [Icon.name]: Icon,
    22. },
    23. data() {
    24. return {
    25. iconList: [
    26. 'rectangle',
    27. 'right',
    28. 'wrong',
    29. 'arrow-left',
    30. 'arrow-right',
    31. 'arrow-up',
    32. 'arrow-down',
    33. 'invisible',
    34. 'visible',
    35. 'service',
    36. 'setting',
    37. 'close',
    38. 'refresh',
    39. 'edit',
    40. 'sort',
    41. 'info',
    42. 'question',
    43. 'security',
    44. 'rmb',
    45. 'wait',
    46. 'check',
    47. 'checked/success',
    48. 'check-disabled',
    49. 'clear/fail',
    50. 'warn',
    51. 'info-solid',
    52. 'scan',
    53. 'share',
    54. 'back',
    55. 'card-bag',
    56. 'message',
    57. 'order',
    58. 'balance',
    59. 'coupon',
    60. 'address-book',
    61. 'mobile-phone',
    62. 'calendar',
    63. 'home',
    64. 'discovery',
    65. 'switch',
    66. 'time',
    67. 'search',
    68. 'user',
    69. 'camera',
    70. 'clock',
    71. 'delete',
    72. 'profession',
    73. 'id-card',
    74. 'authentication',
    75. 'location',
    76. 'filter',
    77. 'motor-vehicle',
    78. 'phone',
    79. 'volumn',
    80. ],
    81. }
    82. },
    83. }
    84. </script>
    85.  

    svg图标

    Icon 图标 - 图3

    1. <template>
    2. <div class="md-example-child md-example-child-icon md-example-child-icon-1">
    3. <div class="md-example-item-s">
    4. <md-icon name="spinner" size="lg" style="-webkit-filter:invert(1)"></md-icon>
    5. <p>spinner</p>
    6. </div>
    7. <div class="md-example-item-s">
    8. <md-icon name="success-color" size="lg" svg></md-icon>
    9. <p>success-color</p>
    10. </div>
    11. <div class="md-example-item-s">
    12. <md-icon name="warn-color" size="lg" svg></md-icon>
    13. <p>warn-color</p>
    14. </div>
    15. </div>
    16. </template>
    17. <script>
    18. import {Icon} from 'mand-mobile'
    19. export default {
    20. name: 'icon-demo',
    21. components: {
    22. [Icon.name]: Icon,
    23. },
    24. }
    25. </script>
    26.  

    大小

    Icon 图标 - 图4

    1. <template>
    2. <div class="md-example-child md-example-child-icon md-example-child-icon-2">
    3. <div class="md-example-item-s">
    4. <md-icon name="location" size="xs"></md-icon>
    5. <p>xs</p>
    6. </div>
    7. <div class="md-example-item-s">
    8. <md-icon name="location" size="sm"></md-icon>
    9. <p>sm</p>
    10. </div>
    11. <div class="md-example-item-s">
    12. <md-icon name="location" size="md"></md-icon>
    13. <p>md</p>
    14. </div>
    15. <div class="md-example-item-s">
    16. <md-icon name="location" size="lg"></md-icon>
    17. <p>lg</p>
    18. </div>
    19. </div>
    20. </template>
    21. <script>
    22. import {Icon} from 'mand-mobile'
    23. export default {
    24. name: 'icon-demo',
    25. components: {
    26. [Icon.name]: Icon,
    27. },
    28. }
    29. </script>
    30.  

    颜色

    Icon 图标 - 图5

    1. <template>
    2. <div class="md-example-child md-example-child-icon md-example-child-icon-3">
    3. <div class="md-example-item-s">
    4. <md-icon name="security" color="gray"></md-icon>
    5. <p>gray</p>
    6. </div>
    7. <div class="md-example-item-s">
    8. <md-icon name="security" color="orange"></md-icon>
    9. <p>orange</p>
    10. </div>
    11. <div class="md-example-item-s">
    12. <md-icon name="security" color="blue"></md-icon>
    13. <p>blue</p>
    14. </div>
    15. <div class="md-example-item-s">
    16. <md-icon name="security" color="purple"></md-icon>
    17. <p>purple</p>
    18. </div>
    19. </div>
    20. </template>
    21. <script>
    22. import {Icon} from 'mand-mobile'
    23. export default {
    24. name: 'icon-demo',
    25. components: {
    26. [Icon.name]: Icon,
    27. },
    28. }
    29. </script>
    30.  

    API

    Icon Props

    属性说明类型默认值备注
    name图标名称String--
    size图标大小Stringmdxs, sm, md, lg
    color图标颜色StringcurrentColor-
    svg使用svg图标Booleanfalse-

    附录

    自定义svg图标

    自定义svg图标需使用svg-sprite-loader,svg文件名即图标名称

    • 安装依赖
    1. npm install svg-sprite-loader --save-dev
    • webpack配置
    1. const path = require('path')
    2. module.exports = {
    3. module: {
    4. loaders: [
    5. {
    6. test: /\.svg$/i,
    7. loader: 'svg-sprite-loader',
    8. include: [
    9. // 将某个路径下所有svg交给 svg-sprite-loader 插件处理
    10. path.resolve(__dirname, 'src/my-project-svg-folder')
    11. ],
    12. }
    13. ]
    14. }
    15. }
    • 引入图标
    1. <template>
    2. <div>
    3. <md-icon name="hello" svg></md-icon>
    4. <md-icon name="world" svg></md-icon>
    5. </div>
    6. </template>
    7. <script>
    8. import 'src/my-project-svg-folder/hello.svg'
    9. import 'src/my-project-svg-folder/world.svg'
    10. import { Icon } from 'mand-mobile'
    11. export default {
    12. name: 'icon-demo',
    13. components: {
    14. [Icon.name]: Icon
    15. }
    16. }
    17. </script>

    引入本地字体文件

    注意:webpack配置url-loader需要包含mand-mobile

    • 重置css中的图标字体
    1. @font-face{
    2. font-family: Mand-Mobile-Icon;
    3. font-style: normal;
    4. font-weight: 400;
    5. src: url(~mand-mobile/components/icon/iconfont.woff) format("woff"),url(~mand-mobile/components/icon/iconfont.woff) format("truetype")
    6. }
    • 自定义主题时重置stylus变量
    1. icon-font-family = url("./iconfont.woff") format("woff"), url("./iconfont.ttf") format("truetype")