简体   繁体   English

Fontawesome 5 React 品牌图标不起作用 - 如何解决?

[英]Fontawesome 5 React Brand Icons not working - how to fix it?

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import '@fortawesome/fontawesome-free-solid';
import '@fortawesome/free-brands-svg-icons';

In rendering code:在渲染代码中:

<FontAwesomeIcon icon={'facebook'} />

<FontAwesomeIcon icon={['fab','facebook']} />

<FontAwesomeIcon icon={['fab','facebook-f']} />

Nothing works.没有任何效果。 I have the following errors:我有以下错误:

backend.js:6 Could not find icon {prefix: "fab", iconName: "facebook"} 
    in FontAwesomeIcon (created by MyView)
    in DashboardView (created by Router.Consumer)
    in Router.Consumer (created by Route)
    in Route

What am I missing?我错过了什么?

I saw someone's advice to import specific objects like -我看到有人建议导入特定对象,例如-

import { faFacebookF } from '@fortawesome/free-brands-svg-icons'

from here Font Awesome 5 use social/brand icons in React (and it's not a duplicate).从这里Font Awesome 5 在 React 中使用社交/品牌图标(它不是重复的)。

But I don't want to import specific objects, because my users should be able to use any icons, and it's specified in the model.但我不想导入特定对象,因为我的用户应该能够使用任何图标,并且它在 model 中指定。

It's also unclear how these icons all work.目前还不清楚这些图标是如何工作的。

I had to change the import to:我不得不将导入更改为:

import { library } from '@fortawesome/fontawesome-svg-core';
import { fab } from '@fortawesome/free-brands-svg-icons';

and add the following code:并添加以下代码:

library.add(fab);

After these changes everything started working.在这些更改之后,一切都开始工作了。

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

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