12

I have the following code for a menu and menu button. I am using Vue CLI 3 and Vuetify

<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Material+Icons">
...
<v-navigation-drawer fixed app v-model="drawer">
  <MyMenu/>
</v-navigation-drawer>
<v-toolbar fixed app>
  <v-toolbar-title class="headline text-uppercase">
    <v-toolbar-side-icon @click.stop="drawer = !drawer"/>
  </v-toolbar-title>
</v-toolbar>

The code works great when the computer is online. However when the computer is offline the menu button icon doesn't show up. Instead it is just replaced with the text 'MENU'. I have looked into installing (vue-material-design-icons, material-design-icons and material-design-icons-iconfont) via npm but have not had any luck getting the icon to display when the computer is offline. I'm not sure if there's a special way to wire it together that I'm unaware of. Can anyone provide insight as to how to solve this issue?

ekjcfn3902039
  • 1,673
  • 3
  • 29
  • 54
  • You'll have to self-host. It would help if you detailed what you tried, and what went wrong attempting it. – ceejayoz Dec 10 '18 at 19:57
  • Unfortunately I did not write down all my attempts, results, etc. The list would be too long – ekjcfn3902039 Dec 10 '18 at 19:59
  • Well, the accepted answer in the SO thread you linked looks like the right way to go about it. Give it a shot and come back with specific issues you encounter for us to fix. – ceejayoz Dec 10 '18 at 20:07
  • I did an npm install of material-design-icons, modified the node_modules/material-design-icons/iconfont/material-icons.css file to contain relative urls (ex:url("node_modules/material-design-icons/iconfont/MaterialIcons-Regular.woff), restarted the server, forced a page refresh and the icon is still missing – ekjcfn3902039 Dec 10 '18 at 20:30
  • OK, so now check the browser console. See if the fonts are attempting to load, and look for any errors. – ceejayoz Dec 10 '18 at 20:30
  • The browser console doesn't have any font errors, yet the images do not load – ekjcfn3902039 Dec 10 '18 at 20:35
  • Are you ``ing `node_modules/material-design-icons/iconfont/material-icons.css` anywhere in your HTML at all? – ceejayoz Dec 10 '18 at 20:46
  • Yes, the href is set to the node_modules...css file. So, I removed the 2 googleapis.com links shown above with one that points to the local css file. – ekjcfn3902039 Dec 10 '18 at 20:56
  • Do you see a call to that URL in the Network tab of your browser's developer console? Does it complete successfully? Can you deploy this somewhere we can take a look? – ceejayoz Dec 10 '18 at 20:57
  • Will the application be online at least initially? If so, you may want to just use a ServicevWorker to cache the fonts. – Jackson Miller Dec 11 '18 at 04:48

3 Answers3

10

Vuetify address this in their documentation:

https://vuetifyjs.com/en/framework/icons#installing-fonts

Essentially:

npm install material-design-icons-iconfont -D

Then:

// main.js
import 'material-design-icons-iconfont/dist/material-design-icons.css' // Ensure you are using css-loader
import Vue from 'vue'
import Vuetify from 'vuetify'

Vue.use(Vuetify, {
  iconfont: 'md'
})
JTInfinite
  • 360
  • 4
  • 14
5

ok, I finally got it working in VS Code.

npm install material-design-icons-iconfont

COPY the folder from the node_modules into you public/css folder (This is what I didn't do before)

Modify the material-design-icons.css file by changing the urls to start with

 url('/css/material-design-icons-iconfont/dist/fonts/MaterialIcons-Regular

- in the index.html page of your project, add

<link rel="stylesheet" href="css/material-design-icons-iconfont/dist/material-design-icons.css">
ekjcfn3902039
  • 1,673
  • 3
  • 29
  • 54
0

my friends, https://vuetifyjs.com/en/features/icon-fonts/#material-design-icons

  1. first install mdi with npm install @mdi/font -D or yarn add @mdi/font -D
  2. import in vuetify file import '@mdi/font/css/materialdesignicons.css' // Ensure you are using css-loader
  3. and set in config export default new Vuetify({ icons: { iconfont: 'mdi', // default - only for display purposes }, })
Pirooz Jenabi
  • 440
  • 5
  • 7