Skip to content
欢迎扫码关注公众号

Vue.js 使用 FontAwesome

这里以使用微信和支付宝的 Icon 为例。

步骤

  1. 安装包

    其中 fontawesome-svg-core 为核心包,free-solid-svg-icons 为默认的 fas 资源包,free-brands-svg-icons 为品牌图标的 fab 资源包。
    另外这里使用的 vue 2.x ,需要安装 vue-fontawesome@latest 包。

    bash
    npm i --save @fortawesome/fontawesome-svg-core
    npm i --save @fortawesome/free-solid-svg-icons
    npm i --save @fortawesome/free-brands-svg-icons
    npm i --save @fortawesome/vue-fontawesome@latest
  2. main.js 中导入组件和图标

    javascript
    import { library } from '@fortawesome/fontawesome-svg-core'
    import { faWeixin, faAlipay } from '@fortawesome/free-brands-svg-icons'
    import { faRetweet, faArrowCircleDown } from '@fortawesome/free-solid-svg-icons'
    import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
    
    library.add(faWeixin, faAlipay)
    library.add(faRetweet, faArrowCircleDown)
    
    Vue.component('font-awesome-icon', FontAwesomeIcon)
  3. 在页面展示图片

    xml
    <font-awesome-icon :icon="['fab', 'weixin']" style="color: #03dd6c;" />
    <font-awesome-icon :icon="['fab', 'alipay']" style="color: #1977ff;" />

其它包

除了上面用到的包之外,还有如下这些,其中 pro 开头的几个包是要付费使用的。
安装方式和上面的类似。

package nameprefix
free-solid-svg-iconsfas
free-regular-svg-iconsfar
free-brands-svg-iconsfab
pro-solid-svg-iconsfas
pro-regular-svg-iconsfar
pro-light-svg-iconsfal
pro-duotone-svg-iconsfad

链接

  1. @fortawesome_vue-fontawesome - npm
  2. GitHub - FortAwesome_vue-fontawesome_ Font Awesome 5 Vue component

Page Layout Max Width

Adjust the exact value of the page width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the page layout
A ranged slider for user to choose and customize their desired width of the maximum width of the page layout can go.

Content Layout Max Width

Adjust the exact value of the document content width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the content layout
A ranged slider for user to choose and customize their desired width of the maximum width of the content layout can go.