5

有没有办法在 Vue 中安装 fontawesome?我尝试了一些教程,但它们都无用且不起作用或图标为空或插件根本不渲染!!!!我不想通过脚本导入字体,我想将它安装在我的应用程序中。我尝试了本教程(https://github.com/FortAwesome/vue-fontawesome),但无论我做什么图标都不会呈现,也许有人可以指出我的解决方案?

这是我的代码,但图标甚至不呈现:

import FontAwesomeIcon from '@fortawesome/vue-fontawesome';


export default {
  name: 'App',
  components:{FontAwesomeIcon}
}

<template>
  <div id="app"><font-awesome-icon icon="spinner" /></div>
</template>

另外,我在控制台中收到错误:

检查未找到一个或多个图标 {prefix: "fas", iconName: "spinner"} {}

4

5 回答 5

10

我认为您可能缺少一些依赖项。请试试

<script>
import fontawesome from "@fortawesome/fontawesome";
import brands from "@fortawesome/fontawesome-free-brands";
// import 1 icon if you just need this one. Otherwise you can import the whole module
import faSpinner from "@fortawesome/fontawesome-free-solid/faSpinner"; 
import FontAwesomeIcon from "@fortawesome/vue-fontawesome";

fontawesome.library.add(brands, faSpinner);
// or .add(brands, solid) if you need the whole solid style icons library/module

export default {
  name: "App",
  components: {
    FontAwesomeIcon
  }
};
</script>

工作示例:https ://codesandbox.io/s/ov6o0xk23y

于 2018-04-27T00:06:58.383 回答
2

请记住加载您正在使用的每个图标。我的图标没有呈现,因为我忘记将它们添加到库中。


模板:

<icon icon="lock" />

JS:

import Vue from 'vue';
import { library } from '@fortawesome/fontawesome-svg-core';
import {
  // import icons here
  faLock,
} from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';

import App from './App.vue';

// add icons to library here
library.add(faLock);

Vue.component('icon', FontAwesomeIcon);

Vue.config.productionTip = false;

new Vue({
  render: h => h(App),
}).$mount('#app');
于 2020-02-01T07:00:21.937 回答
2

Also, in the case that you are using multiple icons, it can be easier to import and load the whole set of icons e.g.

...        
import { fas } from "@fortawesome/free-solid-svg-icons";
    
library.add(fas);
...
于 2020-08-18T00:07:33.083 回答
0

我有同样的问题:

包.json

    "@fortawesome/fontawesome-svg-core": "^1.2.36",
    "@fortawesome/free-brands-svg-icons": "^5.15.4",
    "@fortawesome/free-solid-svg-icons": "^5.15.4",
    "@fortawesome/vue-fontawesome": "^2.0.2",

依靠以前工作的项目,我升级@fortawesome/vue-fontawesome^3.0.0-4,这为我解决了这个问题。

于 2021-08-16T04:39:08.957 回答
0

我收到以下警告,但未显示图标:

"export 'default' (imported as 'FontAwesomeIcon') was not found in '@fortawesome/vue-fontawesome'

我的解决方案是导入特定部分而不是默认

从改变:

import FontAwesomeIcon from '@fortawesome/vue-fontawesome'

import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
于 2021-04-24T00:33:04.327 回答