Last active
January 18, 2019 09:53
-
-
Save Ethanhackett/288cb1651ccff23e0a61a309f7c47533 to your computer and use it in GitHub Desktop.
Font Awesome 5 Pro - Vue.js + Native Script Component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<Span v-bind:class="classes + ' ' + type" v-bind:text="getIcon()" /> | |
</template> | |
<script> | |
/* | |
Setup: | |
1. Setup CSS and Font in Native Script App like this: | |
https://medium.com/@JCAguilera/fontawesome-5-and-nativescript-22653f2b3bac | |
Thanks > Juanky Aguilera | |
2. Save this file into your vue components. | |
3. Copy the icons.json that's included with in the zip from Font Awesome under Metadata. | |
NOTE: You'll have to remember to update this file when you update Font Awesome in the future. | |
4. Declare you global Vue compoent in your main.js file like so: | |
... | |
import fontawesome from './components/modules/fontawesome.vue' | |
Vue.component('icon', fontawesome) | |
... | |
5. Use it anywhere in your Vue templates like this ('alarm-clock' is the name of the Font Awesome Icon): | |
<icon :name="'alarm-clock'" /> | |
*/ | |
const icons = require('../modules/icons.json'); // CONFIGURE this to map to your icons.json file | |
export default { | |
props: { | |
name: { | |
// The name of the font icon you want to use (arrow-right, comment-smile, etc.) | |
type: String, | |
default: 'exclamation-triangle', | |
}, | |
type: { | |
// default Font Awesome icon type (far, fas, fab, fal) | |
type: String, | |
default: 'far', | |
}, | |
// Optional additional classes if you need to add unique styles. | |
classes: { | |
type: String | |
} | |
}, | |
methods: { | |
getIcon: function() { | |
// Return the character not a string | |
return String.fromCharCode(parseInt(icons[this.name].unicode, 16)); | |
} | |
} | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the walkthrough. Got it working, finally!