6

我正在尝试将我的项目从bulma + jQuery切换到buefy。我从 cdn 加载buefyvuefont awesome(buefy@0.6.7,vue@2.5.17,字体真棒 5.2.0)。我对图标的主要问题。我的项目使用了很棒的字体图标。并且默认的 buefy iconPack 是材料设计。它必须支持字体真棒。我试图更改默认图标包,但没有任何作用:

Vue.use(Buefy.default, {
    defaultIconPack: 'fas',
});

同样什么都没有:

Vue.use(Buefy, {
    defaultIconPack: 'fas',
});

所以我需要为每个图标明确指出图标包。

第二个问题是,即使在这种情况下,buefy 也补充fa-lg说我根本不需要。例如对于 b-tab-item 组件

<b-tab-item label="Similarity" icon="search" icon-pack="fas"></b-tab-item>

它呈现:

<i class="fas fa fa-search fa-lg"></i>

是否有可能改变这种 buefy 行为?

4

4 回答 4

15

对于任何可能仍在为此苦苦挣扎的人。我的问题通过在我的main.js

import Buefy from 'buefy'
import 'buefy/dist/buefy.css'

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

library.add(fas);
Vue.component('vue-fontawesome', FontAwesomeIcon);


Vue.use(Buefy, {
  defaultIconComponent: "vue-fontawesome",
  defaultIconPack: "fas",
  customIconPacks: {
    fas: {
      sizes: {
        default: "lg",
        "is-small": "1x",
        "is-medium": "2x",
        "is-large": "3x"
      },
      iconPrefix: ""
    }
  }
});

确保使用以下命令安装所有依赖项npm

$ npm i --save @fortawesome/fontawesome-svg-core
$ npm i --save @fortawesome/free-solid-svg-icons
$ npm i --save @fortawesome/vue-fontawesome

然后你可以在你的组件中使用它,如下所示:

<b-icon
  pack="fas"
  icon="user"
  size="is-large"
  type="is-success"></b-icon>
于 2020-04-05T15:05:18.517 回答
6

这是我在 buefy 中的工作代码

在 main.js 中

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

library.add(fas)
Vue.component('font-awesome-icon', FontAwesomeIcon)
Vue.use(Buefy, { defaultIconPack: 'fas' })

并在index.html

放置在头部标签中

<link
      rel="stylesheet"
      href="https://use.fontawesome.com/releases/v5.6.3/css/all.css"
      integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/"
      crossorigin="anonymous"
    />

确保首先添加fortawesome npm 包

于 2019-05-06T20:04:31.873 回答
3

如果你运行:

yarn add @fortawesome/fontawesome-free

然后导入:

import '../node_modules/@fortawesome/fontawesome-free/js/all.js'

然后它应该工作。从 CDN 导入似乎不起作用。

于 2019-01-19T17:45:41.067 回答
1

在原始答案的基础上。这是我使用 CDN 的工作代码:

main.js

import Vue from 'vue'
import App from './App.vue'
import Buefy from 'buefy';
import 'buefy/dist/buefy.css'

Vue.use(Buefy, {
  defaultIconPack: 'fas'
});

Vue.config.productionTip = false

new Vue({
  render: h => h(App),
}).$mount('#app')

模板

<template>

  <div class="container">
    <b-tabs
      is-boxed>
        <b-tab-item label="Search" icon="search"></b-tab-item>
        <b-tab-item label="Music" icon="music"></b-tab-item>
        <b-tab-item label="Videos" icon="video"></b-tab-item>
    </b-tabs>
  </div>
</template>

索引.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
    <title>buefy-test</title>
  </head>
  <body>
    <noscript>
      <strong>We're sorry but buefy-test doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
    </noscript>
    <div id="app"></div>
    <!-- built files will be auto injected -->
  </body>
</html>
于 2019-01-19T20:57:22.103 回答