为什么我的fontawesome偶像在我的下一个项目中呈现?

发布于 2025-02-11 12:49:44 字数 848 浏览 1 评论 0原文

我有一个下一个项目。

但是,图标并未显示在网页上。我什至在“检查元素”和“父级”中检查了,图标元素不存在。

以下是我的_app.js文件:

import '../styles/globals.css'

import { config } from '@fortawesome/fontawesome-svg-core'
import '@fortawesome/fontawesome-svg-core/styles.css'
config.autoAddCss = false

function MyApp({ Component, pageProps }) {
  return <Component {...pageProps} />
}

export default MyApp

下面是我的index.js文件,在页面目录中:

import React, { Fragment } from "react"
import Head from 'next/head'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import '../node_modules/@fortawesome/fontawesome-svg-core/styles.css'

export default function Home() {
  return (
    <Fragment>
      <FontAwesomeIcon icon="fa-brands fa-facebook-f" />
    </Fragment>
  )
}

为什么我的图标渲染不进行以及如何修复? 提前致谢。

I have a Next.js project where I am using fontawesome icons.

However, the icon does not show up on the web page. I even checked under inspect element and in the parent div and the icon element is not there.

Below is my _app.js file:

import '../styles/globals.css'

import { config } from '@fortawesome/fontawesome-svg-core'
import '@fortawesome/fontawesome-svg-core/styles.css'
config.autoAddCss = false

function MyApp({ Component, pageProps }) {
  return <Component {...pageProps} />
}

export default MyApp

And below is my index.js file in the pages directory:

import React, { Fragment } from "react"
import Head from 'next/head'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import '../node_modules/@fortawesome/fontawesome-svg-core/styles.css'

export default function Home() {
  return (
    <Fragment>
      <FontAwesomeIcon icon="fa-brands fa-facebook-f" />
    </Fragment>
  )
}

Why isn't my icon rendering and how do I fix it?
Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

惟欲睡 2025-02-18 12:49:44

您仍然需要将图标导入您的项目。这就是为什么什么都没有显示。这是您的index.js如果使用免费品牌SVG图标:

import React, { Fragment } from 'react'
import Head from 'next/head'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faFacebookF } from '@fortawesome/free-brands-svg-icons'

export default function Home() {
  return (
    <Fragment>
      <FontAwesomeIcon icon={faFacebookF} />
    </Fragment>
  )
}

You still need to import icons into your project. That's why there is nothing showing. This is what your index.js should look like if using the free brands svg icons:

import React, { Fragment } from 'react'
import Head from 'next/head'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faFacebookF } from '@fortawesome/free-brands-svg-icons'

export default function Home() {
  return (
    <Fragment>
      <FontAwesomeIcon icon={faFacebookF} />
    </Fragment>
  )
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文