美文网首页
iView-Admin 引入 FontAwesome

iView-Admin 引入 FontAwesome

作者: 云中漫步2125 | 来源:发表于2018-10-14 04:16 被阅读0次

    参考
    https://fontawesome.com/how-to-use/on-the-web/using-with/vuejs
    https://www.npmjs.com/package/@fortawesome/vue-fontawesome

    安装fontawsome和vuejs的集成组件

    > npm i --save @fortawesome/fontawesome-svg-core \
      npm i --save @fortawesome/free-solid-svg-icons \
      npm i --save @fortawesome/vue-fontawesome
    

    在main.js中引入vue-fontawesome

    import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
    

    在使用到fontawesome的vue页面引入library 和 图标

    import { library } from '@fortawesome/fontawesome-svg-core'
    # 用到哪个图标,就引入哪个
    import { faCoffee } from '@fortawesome/free-solid-svg-icons'
    # 用到哪个图标,就用library引入对应的icon
    library.add(faCoffee)
    

    在template中,用font-awesome-icon 组件引入图标

    <template>
      <div id="app">
        <font-awesome-icon icon="coffee" />
      </div>
    </template>
    

    设置大小

    <font-awesome-icon icon="spinner" size="xs" />
    <font-awesome-icon icon="spinner" size="lg" />
    <font-awesome-icon icon="spinner" size="6x" />
    

    Tips:
    VSCode中,如果先写import {libray} from '@fortawesome/fontawesome-svg-core'
    再写 library.add(faCoffee)
    VSCode 会自动将 import { faCoffee } from '@fortawesome/fontawesome-svg-core' 补上
    这时在写一个 library.add(faSpinner)
    VSCode 会自动将 faSpinner加到import { faCoffee } from '@fortawesome/fontawesome-svg-core' 中,变成 import { faCoffee, faSpinner } from '@fortawesome/fontawesome-svg-core'
    效率极高!

    相关文章

      网友评论

          本文标题:iView-Admin 引入 FontAwesome

          本文链接:https://www.haomeiwen.com/subject/imzaaftx.html