我正在使用vue.js和vuetify。我想添加一个图标,但不起作用。(未呈现)
我怎样才能解决这个问题?
请参考以下代码
main.js
import Vue from 'vue'
import Vuetify from "vuetify";
import "vuetify/dist/vuetify.min.css";
Vue.use(Vuetify);
Run Code Online (Sandbox Code Playgroud)
index.html
<link href='https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons' rel="stylesheet">
Run Code Online (Sandbox Code Playgroud)
calendar.vue
<i class="material-icons">
keyboard_arrow_down
</i>
Run Code Online (Sandbox Code Playgroud)
我希望它看起来像一个图标,而不是代码
Ben*_*enB 54
通过 vuetify-loader 1.2.2 安装的 Vuetify 2.1.3 存在此问题
似乎以前的解决方案不起作用,因为默认图标库已更改为 mdi-font。
解决方案是:
yarn add @mdi/font
Run Code Online (Sandbox Code Playgroud)
并在文件中main.js
(或plugins/vueitfy.js
如果存在)在导入下方添加此行
import '@mdi/font/css/materialdesignicons.css'
Run Code Online (Sandbox Code Playgroud)
Has*_*der 27
使用Vue CLI 3,我们在src文件夹中没有index.html,因此您也可以
npm install --save material-design-icons-iconfont
Run Code Online (Sandbox Code Playgroud)
并将其导入main.js文件中
import 'material-design-icons-iconfont/dist/material-design-icons.css'
Run Code Online (Sandbox Code Playgroud)
小智 7
为我工作:
npm install @mdi/font
Run Code Online (Sandbox Code Playgroud)
然后把它放在 plugins/vuetify.js 中:
import '@mdi/font/css/materialdesignicons.css'
Run Code Online (Sandbox Code Playgroud)
使用 "vuetify": "^2.3.19", "vue": "^2.6.12",
如果您使用 Nuxt.js,您可能会面临完全相同的问题。为了解决这个问题,你必须在你的 CSS 中声明 Material Design 图标...通过 CDN,例如,如下:
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
{
rel: 'stylesheet',
href:
'https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons'
}
]
Run Code Online (Sandbox Code Playgroud)
小智 6
如果您将 Nuxt 与 Vuetify 一起使用,并且 Material 图标不会显示在 Firefox 中:
npm install import @mdi/font
Run Code Online (Sandbox Code Playgroud)
然后在您nuxt.config.js
的字段中添加以下条目css
:
css: ["@mdi/font/css/materialdesignicons.css"]
Run Code Online (Sandbox Code Playgroud)