【问题标题】:Could not find one or more icon(s) Warning with vuejs application找不到一个或多个图标 vuejs 应用程序警告
【发布时间】:2019-11-05 13:43:52
【问题描述】:

我无法修复警告:

找不到一个或多个图标 {prefix: "far", iconName: "square"} {}"(附截图) 当我更改“typeOfAreaClass”的值或从“areaClass”中选择“安全区域”时弹出警告

这是带有“方形”图标的 v-select 菜单截图:

我尝试安装字体真棒库。它没有帮助。我发现的一件事是,当我将道具“multiple”添加到 v-select 组件时会出现警告。如果我删除该道具,则没有警告。但它扼杀了目的。这对您提出建议有帮助吗?我的字体真棒离子工作正常。只有 v-select prop 'multiple' 会产生警告。

这是 HTML 代码

  <v-flex xs12 md4 sm4  >
    <v-select
    class="myfont1 mt-3 pa-0 customDecoration text-xs-right" 
    @change="assignHazGroups"
    :items="typeOfAreaClassItems"
    v-model="typeOfAreaClassSelect"
    style="max-width:170px;"
    dense
    ></v-select> 
  </v-flex>

  <v-flex xs12 md4 sm4  >
    <v-select
    class="myfont1 mt-3 pa-0 mx-0 customDecoration" 
    @change="safeAreaFilter"
    :items="typeOfAreaClassSelect ==='American' ?areaClassAmericanItems:areaClassEuropeanItems"
    v-model="areaClassSelect"
    style="max-width:220px;"
    dense
    ></v-select> 
  </v-flex>

  <v-flex xs12 md4 sm4 class="ma-0 pa-0"
  >
    <v-select
    class="myfont1 mt-3 pa-0 mx-0 customDecoration"
    :items="typeOfAreaClassSelect =='American' ?hazGroupAmericanItems:hazGroupEuropeanItems"
    v-model="hazGroupSelect"
    multiple
    small-chips
    style="max-width:350px;"
    dense
    ></v-select>    

  </v-flex>

这里是数组变量

typeOfAreaClassItems:["American","European"],
            areaClassAmericanItems:[
                "Safe Area",
                "Class I, Div 1/Class I, Div 2",
                "Class I, Div 1",
                "Class I, Div 2",
            ],
            areaClassEuropeanItems:[
                "Safe Area",
                "Zone-1/Zone-2",
                "Zone-1",
                "Zone-2"
            ],
            hazGroupAmericanItems:[
                "Group A",
                "Group B",
                "Group C",
                "Group D",
                "NA"
            ],
            hazGroupEuropeanItems:[
                "IIC",
                "IIB+H2",
                "IIB",
                "IIA",
                "NA"
            ],
            eleCertItems:[
                "CSA",
                "UL",
                "ATEX",
                "FM",
                "PESO",
                "JIS (Japan)",
                "GOST (Russia)"
            ],
            
            
  //computed variables          
            typeOfAreaClassSelect:{
                get () {
                    return this.$store.getters.typeOfAreaClassSelect
                },
                set (value) {
                    this.$store.dispatch('setTypeOfAreaClassSelect',{data:value})
                }
            },
            areaClassSelect:{
                get () {
                    return this.$store.getters.areaClassSelect
                },
                set (value) {
                    this.$store.dispatch('setAreaClassSelect',{data:value})
                }
            },
            hazGroupSelect:{
                get () {
                    return this.$store.getters.hazGroupSelect
                },
                set (value) {
                    this.$store.dispatch('setHazGroupSelect',{data:value})
                }
            },
            eleCertSelect:{
                get () {
                    return this.$store.getters.eleCertSelect
                },
                set (value) {
                    this.$store.dispatch('setEleCertSelect',{data:value})
                }
            },
            
            

这里是函数

assignHazGroups(){
    if(this.typeOfAreaClassSelect === "American"){
        this.areaClassSelect = "Class I, Div 2"
        this.hazGroupSelect = [
            "Group A",
            "Group B"
        ]
    }
    else{
        this.areaClassSelect = "Zone-2"
        this.hazGroupSelect = [
            "IIB",
            "IIA"
        ]
    }
},
safeAreaFilter(){
    if(this.areaClassSelect === "Safe Area"){
        this.hazGroupSelect = ["NA"]
    }
    else{
        if(this.typeOfAreaClassSelect === "American"){
            this.hazGroupSelect = [
                "Group A",
                "Group B"
            ]
        }
        else{
            this.hazGroupSelect = [
                "IIB",
                "IIA"
            ]
        }
    }
},

当我调用@change 事件并调用函数时,它会出现。需要摆脱这个警告。代码运行良好。

【问题讨论】:

  • 您是否在应用程序中安装了 font awesome 图标包?
  • 感谢您的回复。不,我还没有安装字体真棒图标包。但我的其他图标工作正常。就是这个……而且我没有在这个 html 代码块中使用任何很棒的字体图标。是因为字体很棒的东西,我收到了警告吗?
  • 是的。 far 是字体很棒的图标类。
  • 好的,谢谢。我将安装 font-awesome 库,看看它是否有效..
  • 我尝试安装字体真棒库。它没有帮助。我发现的一件事是,当我将道具“multiple”添加到 v-select 组件时会出现警告。如果我删除该道具,则没有警告。但它扼杀了目的。这对您提出建议有帮助吗?我的字体真棒离子工作正常。只有 v-select 道具 'multiple' 正在创建警告。提前致谢

标签: javascript vue.js icons warnings vuetify.js


【解决方案1】:

问题

Vuetify 的 v-simple-checkbox 组件使用图标 checkboxOff according to the documentation

引发的错误是在 Font Awesome 中找不到图标 far fa-square。这是因为在版本 5 中,图标是 fas fa-square from the documentation

Font Awesomes' FaSvg library assumes that all of the icons are prepended with fas which is why the icon far fa-square cannot be found.

解决方案

解决方法是用正确的值覆盖checkboxOff 图标。

setup/vuetify.js

// All of the import and setup
import Vue from 'vue';
import Vuetify from 'vuetify/lib';

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

Vue.component('font-awesome-icon', FontAwesomeIcon)
library.add(fas)

Vue.use(Vuetify);

// The configuration
export default new Vuetify({
  icons: {
    iconfont: "faSvg",
    values: {
      // The important part!!
      checkboxOff: {
        component: FontAwesomeIcon,
        props: {
          icon: ['fa', 'square'],
        }
      }
    }
  },
});

ma​​in.js

import App from './App.vue';
import vuetify from './setup/vuetify';

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

【讨论】:

    【解决方案2】:

    我最初使用 Daniel Butler 的答案,但在单选按钮上遇到了同样的问题。然后我意识到更好的解决方法是在 Vuetify 中实际导入常规图标集,就像导入实体图标一样。

    setup/vuetify.js

    import { library } from '@fortawesome/fontawesome-svg-core';
    import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
    import { fas } from '@fortawesome/free-solid-svg-icons';
    import { far } from '@fortawesome/free-regular-svg-icons';
    
    Vue.component('font-awesome-icon', FontAwesomeIcon);
    library.add(fas);
    library.add(far);
    

    如果您还没有安装常规图标,则需要运行:

    $ yarn add @fortawesome/free-regular-svg-icons -D
    // or
    $ npm install @fortawesome/free-regular-svg-icons -D
    

    通过此更改,我的所有图标都可以正常工作,而无需任何进一步的自定义配置。

    【讨论】:

      【解决方案3】:

      我在 vuetify 插件 js 文件中更改了 iconfont。

      在 /plugins/vuetify.js 文件中

      更改了以下代码

      Vue.use(Vuetify, {
        iconfont: 'faSvg',
      })

      到这里

      Vue.use(Vuetify, {
        iconfont: 'md',
      })

      这基本上修复了图标警告。

      【讨论】:

      • 这会将整个字体库从 Font Awesome 替换为 Google 的 Material Design,这在某种程度上解决了这个问题,但它类似于把婴儿和洗澡水一起扔出去。
      猜你喜欢
      • 2019-05-13
      • 2018-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-02
      • 1970-01-01
      • 1970-01-01
      • 2014-06-23
      相关资源
      最近更新 更多