简体   繁体   English

FontAwesome 图标未出现在 typescript 文件中

[英]FontAwesome icon not appearing in typescript file

I have a typescript file with.tsx extension and I am using React.我有一个扩展名为 .tsx 的 typescript 文件,我正在使用 React。 I am trying to display a fontawesome icon but all I get is an empty square box.我正在尝试显示一个 fontawesome 图标,但我得到的只是一个空的方框。

this is how I am install font-awesome using npm:这就是我使用 npm 安装 font-awesome 的方式:

npm install --save font-awesome

this is how I import the font-awesome library in my.tsx file:这就是我在 my.tsx 文件中导入 font-awesome 库的方式:

 import 'font-awesome/css/font-awesome.min.css';

and this is how I am calling my icon in html code, inside the.tsx file:这就是我在 .tsx 文件中的 html 代码中调用我的图标的方式:

      <div id="info">
            <i class="fas fa-angle-right"></i>

            <button class="accordion">Items</button>
       </div>

The button just wouldn't come out and I have been trying for hours.按钮就是不会出来,我已经尝试了几个小时。 Would appreciate some insights.将不胜感激一些见解。 Thanks in advance!提前致谢!

Since you are using react, maybe try doing it the react way?既然你正在使用反应,也许尝试用反应的方式来做?

 npm i --save @fortawesome/fontawesome-svg-core npm install --save @fortawesome/free-solid-svg-icons npm install --save @fortawesome/react-fontawesome
import ReactDOM from 'react-dom'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faAngleRight } from '@fortawesome/free-solid-svg-icons'

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

ReactDOM.render(element, document.body)

https://fontawesome.com/how-to-use/on-the-web/using-with/react https://fontawesome.com/how-to-use/on-the-web/using-with/react

Then you can also use all the build in features https://fontawesome.com/how-to-use/on-the-web/using-with/react#features然后您还可以使用所有内置功能https://fontawesome.com/how-to-use/on-the-web/using-with/react#features

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM