图标在Vue2 + Vuetify 2应用中未渲染

huangapple go评论83阅读模式
英文:

icons are not rendering in Vue2 + Vuetify 2 app

问题

在我的Vue2 + Vuetify2应用程序中,图标无法在显示时渲染,但DOM中存在这些元素(图标)。

package.json

{
  "name": "sample",
  "version": "0.1.0",
  "dependencies": {
    "core-js": "^3.8.3",
    "vue": "^2.6.14",
    "vuetify": "^2.6.0"
  },
  "devDependencies": {
    "@babel/core": "^7.12.16",
    "@babel/eslint-parser": "^7.12.16",
    "@mdi/font": "^7.1.96",
    "@vue/cli-plugin-babel": "~5.0.0",
    "@vue/cli-plugin-eslint": "~5.0.0",
    "@vue/cli-service": "~5.0.0",
    "eslint": "^7.32.0",
    "eslint-plugin-vue": "^8.0.3",
    "sass": "~1.32.0",
    "sass-loader": "^10.0.0",
    "vue-cli-plugin-vuetify": "~2.5.8",
    "vue-template-compiler": "^2.6.14",
    "vuetify-loader": "^1.7.0"
  }
}

main.js

import Vue from 'vue'
import App from './App.vue'
import vuetify from './plugins/vuetify'

Vue.config.productionTip = false

new Vue({
  vuetify,
  icons: {
    iconfont: 'mdi', // 默认值,仅供显示用途
  },
  render: (h) => h(App),
}).$mount("#app");

index.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="icon" href="<%= BASE_URL %>favicon.ico">
  <title><%= htmlWebpackPlugin.options.title %></title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.14.0/css/all.css" crossorigin="anonymous">
  <link href="https://cdn.jsdelivr.net/npm/@mdi/font@6.x/css/materialdesignicons.min.css" rel="stylesheet">
</head>

<body>
  <noscript>
    <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled.
      Please enable it to continue.</strong>
  </noscript>
  <div id="app"></div>
  <!-- 构建文件将自动注入 -->
</body>

</html>

应用程序中使用了vuetify-icons的组件:

<template>
  <v-row justify="space-around" style="margin: 25px; border:5px solid #f00; height: 100px;">
    <v-icon size="large" color="green-darken-2" icon="mdi-domain"></v-icon>

    <v-icon size="large" color="blue-darken-2" icon="mdi-message-text"></v-icon>

    <v-icon size="large" color="purple-darken-2" icon="mdi-dialpad"></v-icon>

    <v-icon size="large" color="teal-darken-2" icon="mdi-email"></v-icon>

    <v-icon size="large" color="blue-grey-darken-2" icon="mdi-call-split"></v-icon>

    <v-icon size="large" color="orange-darken-2" icon="mdi-arrow-up-bold-box-outline"></v-icon>
  </v-row>
</template>

<script>
export default {
  name: 'App',
  data: () => ({

  }),
}
</script>

在浏览器中的渲染效果如下图所示:

图标在Vue2 + Vuetify 2应用中未渲染

英文:

In my Vue2 + Vuetify2 the icons are not rendering in the display however the elements(icon) are present in the DOM

package.json

{
 &quot;name&quot;: &quot;sample&quot;,
 &quot;version&quot;: &quot;0.1.0&quot;,
&quot;dependencies&quot;: {
  &quot;core-js&quot;: &quot;^3.8.3&quot;,
  &quot;vue&quot;: &quot;^2.6.14&quot;,
  &quot;vuetify&quot;: &quot;^2.6.0&quot;
},
&quot;devDependencies&quot;: {
 &quot;@babel/core&quot;: &quot;^7.12.16&quot;,
 &quot;@babel/eslint-parser&quot;: &quot;^7.12.16&quot;,
 &quot;@mdi/font&quot;: &quot;^7.1.96&quot;,
 &quot;@vue/cli-plugin-babel&quot;: &quot;~5.0.0&quot;,
 &quot;@vue/cli-plugin-eslint&quot;: &quot;~5.0.0&quot;,
 &quot;@vue/cli-service&quot;: &quot;~5.0.0&quot;,
 &quot;eslint&quot;: &quot;^7.32.0&quot;,
 &quot;eslint-plugin-vue&quot;: &quot;^8.0.3&quot;,
 &quot;sass&quot;: &quot;~1.32.0&quot;,
 &quot;sass-loader&quot;: &quot;^10.0.0&quot;,
 &quot;vue-cli-plugin-vuetify&quot;: &quot;~2.5.8&quot;,
 &quot;vue-template-compiler&quot;: &quot;^2.6.14&quot;,
 &quot;vuetify-loader&quot;: &quot;^1.7.0&quot;
},

main.js

import Vue from &#39;vue&#39;
import App from &#39;./App.vue&#39;
import vuetify from &#39;./plugins/vuetify&#39;

Vue.config.productionTip = false

new Vue({
 vuetify,
 icons: {
 iconfont: &#39;mdi&#39;, // default - only for display purposes
},
 render: (h) =&gt; h(App),
}).$mount(&quot;#app&quot;);

index.html

&lt;!DOCTYPE HTML&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
&lt;meta charset=&quot;utf-8&quot;&gt;
&lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;
&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width,initial-scale=1.0&quot;&gt;
&lt;link rel=&quot;icon&quot; href=&quot;&lt;%= BASE_URL %&gt;favicon.ico&quot;&gt;
&lt;title&gt;&lt;%= htmlWebpackPlugin.options.title %&gt;&lt;/title&gt;
  &lt;link rel=&quot;stylesheet&quot; href=&quot;https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900&quot;&gt;
  &lt;link rel=&quot;stylesheet&quot; href=&quot;https://use.fontawesome.com/releases/v5.14.0/css/all.css&quot; crossorigin=&quot;anonymous&quot;&gt;
  &lt;link href=&quot;https://cdn.jsdelivr.net/npm/@mdi/font@6.x/css/materialdesignicons.min.css&quot; rel=&quot;stylesheet&quot;&gt;
&lt;/head&gt;
&lt;body&gt;
 &lt;noscript&gt;
  &lt;strong&gt;We&#39;re sorry but &lt;%= htmlWebpackPlugin.options.title %&gt; doesn&#39;t work properly without JavaScript enabled. Please enable it to continue.&lt;/strong&gt;
&lt;/noscript&gt;
&lt;div id=&quot;app&quot;&gt;&lt;/div&gt;
&lt;!-- built files will be auto injected --&gt;

</body>
</html>

And the app component which is making use vuetify-icons

&lt;template&gt;
&lt;v-row justify=&quot;space-around&quot; style=&quot;margin: 25px;  border:5px solid #f00; height: 
100px;&quot;&gt;
 &lt;v-icon
  size=&quot;large&quot;
  color=&quot;green-darken-2&quot;
  icon=&quot;mdi-domain&quot;
&gt;&lt;/v-icon&gt;

&lt;v-icon
  size=&quot;large&quot;
  color=&quot;blue-darken-2&quot;
  icon=&quot;mdi-message-text&quot;
&gt;&lt;/v-icon&gt;

&lt;v-icon
  size=&quot;large&quot;
  color=&quot;purple-darken-2&quot;
  icon=&quot;mdi-dialpad&quot;
&gt;&lt;/v-icon&gt;

&lt;v-icon
  size=&quot;large&quot;
  color=&quot;teal-darken-2&quot;
  icon=&quot;mdi-email&quot;
&gt;&lt;/v-icon&gt;

&lt;v-icon
  size=&quot;large&quot;
  color=&quot;blue-grey-darken-2&quot;
  icon=&quot;mdi-call-split&quot;
&gt;&lt;/v-icon&gt;

&lt;v-icon
  size=&quot;large&quot;
  color=&quot;orange-darken-2&quot;
  icon=&quot;mdi-arrow-up-bold-box-outline&quot;
&gt;&lt;/v-icon&gt;
&lt;/v-row&gt;
&lt;/template&gt;

&lt;script&gt;
 export default {
name: &#39;App&#39;,

data: () =&gt; ({
  
}),
}

</script>

This is how is rendering in the browser

图标在Vue2 + Vuetify 2应用中未渲染

I have checked all these links but futile

> Can someone here please suggest what else is needed to render the material/font-awesome icons in the Vue app?

Thanks!

答案1

得分: 0

你在使用图标的语法错误。对于Vuetify 2,请使用以下代码:

<v-icon
  size="large"
  color="green-darken-2"
>mdi-domain</v-icon>
英文:

You are using the wrong syntax for icons. For Vuetify 2, use the following:

&lt;v-icon
  size=&quot;large&quot;
  color=&quot;green-darken-2&quot;
&gt;mdi-domain&lt;/v-icon&gt;

huangapple
  • 本文由 发表于 2023年3月8日 17:21:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/75671272.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定