简体   繁体   English

无法将 FontAwesome 与 NuxtjS3 一起使用

[英]Unable to use FontAwesome with NuxtjS3

I'm trying to use FontAwesome with NuxtJS but it doesn't work for unknown reasons.我正在尝试将 FontAwesome 与 NuxtJS 一起使用,但由于未知原因它不起作用。

Here is my package.json :这是我的package.json

{
  "private": true,
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview"
  },
  "devDependencies": {
    "nuxt": "3.0.0-rc.6",
    "sass": "^1.54.0",
    "sass-loader": "^13.0.2"
  },
  "dependencies": {
    "@fortawesome/fontawesome-svg-core": "^6.1.2",
    "@fortawesome/free-regular-svg-icons": "^6.1.2",
    "@fortawesome/free-brands-svg-icons": "^6.1.2",
    "@fortawesome/free-solid-svg-icons": "^6.1.2",
    "@fortawesome/vue-fontawesome": "^3.0.1",
    "@nuxtjs/fontawesome": "^1.1.2"
  }
}

Here is my nuxt.config.ts :这是我的nuxt.config.ts

import { defineNuxtConfig } from 'nuxt'

// https://v3.nuxtjs.org/api/configuration/nuxt.config
export default defineNuxtConfig({
    buildModules: ['@nuxtjs/fontawesome'],
    fontawesome: {
        icons: {
            solid: ['faHome']
        }
    }
})

Now pages/index.vue :现在pages/index.vue

<template>
  <div>
    Hello
  </div>
</template>

As you can see I'm not even using any icon in this example, yet my app cannot start due to the following error in the Terminal (when I run npm run dev ).如您所见,在此示例中我什至没有使用任何图标,但由于终端中的以下错误(当我运行npm run dev时),我的应用程序无法启动。

ℹ Vite client warmed up in 440ms                                                                                                                                  12:52:57
ℹ Vite server warmed up in 113ms                                                                                                                                  12:52:57
✔ Vite server built in 812ms                                                                                                                                      12:52:58
✔ Nitro built in 178 ms 
[h3] [unhandled] H3Error: Cannot read properties of undefined (reading 'component')
    at createError (file:///Users/thomasgysemans/Documents/GitHub/vue-portfolio/node_modules/h3/dist/index.mjs:191:15)
    at Server.nodeHandler (file:///Users/thomasgysemans/Documents/GitHub/vue-portfolio/node_modules/h3/dist/index.mjs:381:21) {
  statusCode: 500,
  fatal: false,
  unhandled: true,
  statusMessage: 'Internal Server Error'
}

I don't understand this error and it seems like I am the only one to have it.我不明白这个错误,似乎我是唯一一个拥有它的人。 Also, I'm new to NuxtJS and Vue.另外,我是 NuxtJS 和 Vue 的新手。

I am following the documentation of @nuxtjs/fontawesome , and if I understand it well, I'm doing nothing wrong... Well I hope I made a simple mistake that will be solved lol.我正在关注@nuxtjs/fontawesome 的文档,如果我理解得很好,我没有做错任何事情......好吧,我希望我犯了一个可以解决的简单错误,哈哈。 I really want to use FontAwesome , and it should work as FontAwesome itself provides a documentation on how to use their icons with Vue (but nothing related to NuxtJS).我真的很想使用FontAwesome ,它应该可以工作,因为 FontAwesome 本身提供了有关如何将其图标与 Vue 一起使用的文档(但与 NuxtJS 无关)。

Edit编辑

Also, the app shows this as plain text, in a black background, but it doesn't show my beautiful "Hello".此外,该应用程序将其显示为纯文本,在黑色背景中,但它没有显示我美丽的“你好”。

{
  "statusCode": 404,
  "statusMessage": "Not Found",
  "stack": []
}

Found the answer thanks to 'kissu'.感谢'kissu'找到了答案。 Actually, FontAwesome had given answers at this link: https://fontawesome.com/docs/web/use-with/vue/use-with#nuxt实际上,FontAwesome 在这个链接上给出了答案: https://fontawesome.com/docs/web/use-with/vue/use-with#nuxt

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

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