Created
November 10, 2018 06:46
-
-
Save donvito/21e37bb931ea9e7e70b10aba21653974 to your computer and use it in GitHub Desktop.
Vue.js code to query github API
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
<html> | |
<head> | |
<script src="https://unpkg.com/vue"></script> | |
</head> | |
<body> | |
<div id="app"> | |
<github-repo-list | |
v-for="repo in repos" | |
v-bind:repo="repo" | |
v-bind:key="repo.name" | |
v-bind:key="repo.id"> | |
</github-repo-list> | |
</div> | |
</body> | |
</html> | |
<script> | |
new Vue({ | |
el: '#app', | |
data: { | |
repos : [], | |
}, | |
created(){ | |
fetch("https://api.github.com/users/donvito/repos") | |
.then(response => response.json()) | |
.then((data) => { | |
this.repos = data; | |
console.log(data) | |
}) | |
} | |
}); | |
Vue.component('github-repo-list', { | |
props: ['repo'], | |
template: '<li>{{ repo.id }} / {{ repo.name }}</li>' | |
}) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just open in the browser to test, no need to run in a web server.