gpt4 book ai didi

javascript - 你如何在 nuxt 3 上获得很棒的字体设置

转载 作者:行者123 更新时间:2023-12-05 04:27:56 27 4
gpt4 key购买 nike

当我尝试在我的 nuxt 3 应用程序中渲染这个很棒的字体组件时,我遇到了以下错误,正确地遵循了所有 npm 安装并且无法在没有任何错误的情况下在应用程序中获取图标。

  at WeakMap.set (<anonymous>)  
at normalizePropsOptions (./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:3966:11)
at createComponentInstance (./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6957:23)
at renderComponentVNode (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:171:22)
at Module.ssrRenderComponent (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:608:12)
at _sfc_ssrRender (./.nuxt/dist/server/server.mjs:2939:33)
at renderComponentSubTree (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:253:13)
at renderComponentVNode (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:188:16)
at Module.ssrRenderComponent (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:608:12)
at _sfc_ssrRender (./.nuxt/dist/server/server.mjs:9374:31)

这是破坏应用程序的代码行

<font-awesome-icon :icon="['fas', 'user']" />

nuxt.config 文件

import { defineNuxtConfig } from "nuxt";

export default defineNuxtConfig({
css: ["@/assets/css/tailwind.css"],
build: {
postcss: {
postcssOptions: {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
},
},
},
plugins: ["~/plugins/fontawesome.js"],
buildModules: [
["@pinia/nuxt", { disableVuex: true }],
["@nuxtjs/tailwindcss", { config: "@/tailwind.config.js" }],
],
modules: ["@nuxtjs/tailwindcss"],
});

插件文件

import { library } from "@fortawesome/fontawesome-svg-core";
import { fas } from "@fortawesome/free-solid-svg-icons";
// import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";

export default defineNuxtPlugin((nuxtApp) => {
// nuxtApp.vueApp.component("FontAwesomeIcon", FontAwesomeIcon);
library.add(fas);
});

我使用该插件是因为无论出于何种原因设置 npm @nuxt/fortawesome 都不起作用

包.json


"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.1.1",
"@fortawesome/free-brands-svg-icons": "^6.1.1",
"@fortawesome/free-solid-svg-icons": "^6.1.1",
"@fortawesome/vue-fontawesome": "^2.0.8",
"@supabase/supabase-js": "^1.35.3",
"pinia": "^2.0.14"
}
}

最佳答案

使用我的 solution here , 基于 unplugin-icons能够解决 OP 的问题。

最后,像这样的东西会产生完全相同的结果,但它是通用的、高性能的,而且对于任何类型的 future 库,您只需执行一次结果。

<script setup>
import IconXmark from `~icons/fa6-solid/xmark`
</script>

<template>
<icon-xmark style="font-size: 2em; color: blue" />
</template>

关于javascript - 你如何在 nuxt 3 上获得很棒的字体设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72723309/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com