Skip to content

Instantly share code, notes, and snippets.

@adammcfadden
Last active June 26, 2021 10:18
Show Gist options
  • Save adammcfadden/be35054aaab5c36ab421282e3399a4e3 to your computer and use it in GitHub Desktop.
Save adammcfadden/be35054aaab5c36ab421282e3399a4e3 to your computer and use it in GitHub Desktop.
Vue component for loading minimal fonts with webfontloader
// Vue component for loading minimal fonts with webfontloader
<template>
</template>
<script>
//https://github.com/typekit/webfontloader
import WebFontLoader from 'webfontloader';
export default {
created() {
WebFontLoader.load({
custom: {
// Use FVD notation to include families https://github.com/typekit/fvd
families: ['Rubik:n4,n5,n7'],
// Path to stylesheet that defines font-face
urls: ['/static/assets/fonts/stylesheet.css'],
},
active: this.setFontLoaded,
});
},
methods: {
setFontLoaded() {
this.$emit('font-loaded');
},
},
};
</script>
@VinuRaj
Copy link

VinuRaj commented Mar 22, 2018

Perfect 👍

@dvikas
Copy link

dvikas commented Jul 1, 2018

Thanks, it's working. I used that snippet in App.vue.
WebFontLoader.load({ custom: { families: ['Material Icons'] }, active: this.setFontLoaded })
I am using vuetify theme so I don't need to include css here, because it's alreday loaded.

@traian321
Copy link

Please help me !
I have error message
"window is not defined"

@borodadada
Copy link

it's not work on SSR, and yes "window is not defined"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment