参考
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'
效率极高!
网友评论