Last active
October 15, 2020 18:07
-
-
Save boring-dragon/4cfd2a6f28ea4d173f0557ef0b3e8481 to your computer and use it in GitHub Desktop.
Baivaru Dhivatar Vue component Implementation
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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Baivaru Dhivatar Vue component Implementation</title> | |
| </head> | |
| <body> | |
| <div id="app"> | |
| <baivaru-dhivatar name="ޖިނާސް"></baivaru-dhivatar> | |
| <baivaru-dhivatar name="އަތްފާން"></baivaru-dhivatar> | |
| </div> | |
| <script type="text/x-template" id="baivaru-dhivatar-template"> | |
| <img :src="image" alt="avatar"> | |
| </script> | |
| <!-- Import Vue.js and axios --> | |
| <script src="https://unpkg.com/vue"></script> | |
| <script src="https://unpkg.com/axios/dist/axios.min.js"></script> | |
| <script> | |
| Vue.component('baivaru-dhivatar', { | |
| template: '#baivaru-dhivatar-template', | |
| props: { | |
| name: { | |
| type: String, | |
| required: true | |
| } | |
| }, | |
| data() { | |
| return { | |
| image: "" | |
| } | |
| }, | |
| created() { | |
| var base = this; | |
| axios.get(`https://dhivatars.baivaru.net/api/?name=${this.name}`, { | |
| responseType: "arraybuffer" | |
| }) | |
| .then(response => { | |
| let base64String = btoa( | |
| String.fromCharCode.apply(null, new Uint8Array(response.data)) | |
| ); | |
| base.image = "data:image/png;base64," + base64String; | |
| }) | |
| } | |
| }) | |
| new Vue({ | |
| el: '#app' | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment