我通过npm安装了真棒字体。
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.15",
"@fortawesome/free-solid-svg-icons": "^5.7.2",
"@fortawesome/react-fontawesome": "^0.1.4",
"axios": "^0.18.0",
"jquery": "^3.3.1",
"react": "^16.8.2",
"react-dom": "^16.8.2",
"react-scripts": "2.1.5"
},
但是我该如何在应用程序中使用图标。
<i className="fas fa-home" ></i>
<b> Trang chủ </b>
但是没有用。
答案 0 :(得分:1)
从documentation看来,您首先需要导入要使用的每个图标,然后将其注册到Font Awesome库。然后,当您要使用图标时,将FontAwesomeIcon
导入为React组件,然后将其渲染。
例如:
在App.js中:
import { library } from '@fortawesome/fontawesome-svg-core'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faHome } from '@fortawesome/free-solid-svg-icons'
library.add(faHome)
然后在您的组件文件中:
import React from 'react'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
export default props => {
return (
<span>
<FontAwesomeIcon icon="home"/>
<b>Trang chu</b>
</span>
)
}