gpt4 book ai didi

reactjs - 找不到图标react-fontawesome

转载 作者:行者123 更新时间:2023-12-03 12:59:24 26 4
gpt4 key购买 nike

我有一个关于 React 的项目,我需要将 FontAwesome 集成到其中。我找到官方library并按照自述文件中的说明安装它

$ npm i --save @fortawesome/fontawesome
$ npm i --save @fortawesome/react-fontawesome

当我尝试在我的代码中使用它时,如下所示:

<FontAwesomeIcon icon='plus'/>
<FontAwesomeIcon icon={['fa', 'coffee']}/>

我在控制台上收到此错误:

Could not find icon {prefix: "fas", iconName: "plus"}
Could not find icon {prefix: "fa", iconName: "coffee"}

我尝试将 FontAwesome css 链接包含到头部,但没有帮助。我正在使用npm v4.6.1节点 v8.9.1; react v16.2。

最佳答案

您需要将想要使用的任何图标添加到“库”中以方便引用。

import React from 'react';
import { render } from 'react-dom';
import Hello from './Hello';
import fontawesome from '@fortawesome/fontawesome'
import FontAwesomeIcon from '@fortawesome/react-fontawesome';
import { faCheckSquare, faCoffee } from '@fortawesome/fontawesome-free-solid'

const styles = {
fontFamily: 'sans-serif',
textAlign: 'center',
};

fontawesome.library.add(faCheckSquare, faCoffee);

const App = () => (
<div style={styles}>
<FontAwesomeIcon icon="check-square" /><br /><br />
<FontAwesomeIcon icon="coffee" />
</div>
);

render(<App />, document.getElementById('root'));

在这里查看工作代码: https://codesandbox.io/s/8y251kv448

另外,请阅读以下内容: https://www.npmjs.com/package/@fortawesome/react-fontawesome#build-a-library-to-reference-icons-throughout-your-app-more-conveniently

关于reactjs - 找不到图标react-fontawesome,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48002619/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com