Last active
August 28, 2017 10:57
-
-
Save Timtech4u/bff23e104d0532d33808c8bffe0a913b to your computer and use it in GitHub Desktop.
A Simple API call using Vue.js and Axios
This file contains 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>Vue Axios Example</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.4.2/vue.js"></script> | |
<script src="https://unpkg.com/axios/dist/axios.min.js"></script> | |
</head> | |
<body> | |
<div id="app"> | |
<ul> | |
<li v-for="user in users">{{ user.name }}</li> | |
</ul> | |
</div> | |
<script> | |
new Vue({ | |
el: '#app', | |
data: { | |
users: [] | |
}, | |
created () { | |
var vm = this | |
axios.get('https://jsonplaceholder.typicode.com/users') | |
.then(function (response) { | |
vm.users = response.data | |
}) | |
} | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment