【问题标题】:How to display Fontawesome icons using Unicode and React?如何使用 Unicode 和 React 显示 Fontawesome 图标?
【发布时间】:2020-07-21 15:49:12
【问题描述】:

我正在试验 React,并希望显示一个 Fontawesome 图标列表。

我有一个 JSON 文件,其中包含这样的数据集:

{
  "icons": [
    {
      "name": "Glass",
      "id": "glass",
      "unicode": "f000",
      "created": 1,
      "filter": [
        "martini",
        "drink",
        "bar",
        "alcohol",
        "liquor"
      ],
      "categories": [
        "Web Application Icons"
      ]
    },
    etc

我可以遍历这个并返回并打印每个数据点,但不知道如何显示实际的图标。

我已经尝试过这样使用 unicode:

  return(
    <div>
      <ul>
        <li>
          <span>{data.name}</span>
          <i className="fa">{data.unicode}</i>
        </li>
      </ul>
    </div>
  )

但它只是打印 unicode 值。

有人知道是否可以以这种方式呈现图标吗?

【问题讨论】:

    标签: reactjs font-awesome


    【解决方案1】:

    首先将数字转换为字符串,方法是调用String.fromCharCode

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-20
      • 2020-12-10
      • 2022-01-13
      • 2021-12-22
      • 1970-01-01
      • 1970-01-01
      • 2021-03-27
      • 1970-01-01
      相关资源
      最近更新 更多