当前位置: 首页 > 工具软件 > Splashy Icons > 使用案例 >

React font awesome icons图标

萧芷阳
2023-12-01

菜鸟笔记。

其实官网教程都有:https://fontawesome.com/how-to-use/on-the-web/using-with/react

首先是本地安装:

font awesome根据style和证书把icon分到了几个不同的package,所以需要根据style选择package安装。详情看这里:https://fontawesome.com/how-to-use/javascript-api/setup/importing-icons#icon-names

npm i --save @fortawesome/fontawesome-svg-core
  npm install --save @fortawesome/free-solid-svg-icons
  npm install --save @fortawesome/react-fontawesome

关于--save 和 --save-dev 的区别:https://stackoverflow.com/questions/22891211/what-is-the-difference-between-save-and-save-dev

  • --save-dev is used to save the package for development purpose. Example: unit tests, minification..
  • --save is used to save the package required for the application to run.

使用实例:

import ReactDOM from 'react-dom'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faCoffee } from '@fortawesome/free-solid-svg-icons'

const element = <FontAwesomeIcon icon={faCoffee} />

ReactDOM.render(element, document.body)

配置size:<FontAwesomeIcon icon="coffee" size="xs" />

 

 类似资料: