【问题标题】:Reach and font-awesome到达和字体真棒
【发布时间】:2019-02-12 15:56:55
【问题描述】:

我正在尝试使用 React 中的 font-awesome。我已经设法从https://fontawesome.com/how-to-use/on-the-web/using-with/react 获得了使用stroopwafel 图标的示例。这很好,但可能没那么有用。现在我想添加一个更有用的图标:the exclamation mark。但是,这里的命名标准似乎有些问题,因为当我尝试时:

import { fa-exclamation-triangle } from '@fortawesome/free-solid-svg-icons'

我得到:Syntax error: Unexpected token, expected ,

当我试图删除那些讨厌的-

import { faexclamationtriangle } from '@fortawesome/free-solid-svg-icons'

我收到'@fortawesome/free-solid-svg-icons' does not contain an export named 'faexclamationtriangle'.

那么,我怎么知道这些图标叫什么?

【问题讨论】:

  • 尝试使用lowerCamelCase格式,faExclamationTriangle
  • 似乎已经奏效了,但是下一步我要使用它时该怎么称呼它?
  • 您应该使用与导入它相同的名称来调用它,在这种情况下,faExclamationTriangle 如果您仔细阅读您链接的文档,它们正是这样做的。

标签: reactjs font-awesome


【解决方案1】:

这就是诀窍:

import { faExclamationTriangle } from '@fortawesome/free-solid-svg-icons'

camelCase 和没有烦恼-.

接下来,当你使用它时,你不应该有fa,而不是camelCase,哦,那第二个-呢?继续保持那个!

<FontAwesomeIcon icon="exclamation-triangle"/>

令人困惑?是的,我当然这么认为……

【讨论】:

    猜你喜欢
    • 2013-06-19
    • 2016-02-10
    • 2014-12-10
    • 2020-09-24
    • 2021-06-04
    • 1970-01-01
    • 2014-08-02
    • 2017-12-31
    • 1970-01-01
    相关资源
    最近更新 更多