Skip to content

Instantly share code, notes, and snippets.

@Timtech4u
Last active August 28, 2017 10:57
Show Gist options
  • Save Timtech4u/bff23e104d0532d33808c8bffe0a913b to your computer and use it in GitHub Desktop.
Save Timtech4u/bff23e104d0532d33808c8bffe0a913b to your computer and use it in GitHub Desktop.
A Simple API call using Vue.js and Axios
<!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