Vue.js | Making API calls using Axios

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Vue.js | Making API calls using Axios</title>
</head>
<body style="text-align: center">
<div style="display: inline-block;margin-top: 100px">
<img src="https://ui-avatars.com/api/?size=128" alt="">
<h1 style="margin-bottom: 0">John Doe</h1>
<span>johndoe@email.com</span>
</div>
</body>
</html>
....................
<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>
.................
<script>
const data = {avatar: "https://ui-avatars.com/api/?size=128", name: "john doe", email: "johndoe@email.com"};
var vm = new Vue({
el: '#app',
data: data
});
</script>
<div id="app" style="display: inline-block;margin-top: 100px">
<img v-bind:src="avatar" alt="">
<h1 style="margin-bottom: 0">{{name}}</h1>
<span>{{email}}</span>
</div>
..............,
mounted() {
axios.get('https://randomuser.me/api/')
.then(function (response) {
const user = response.data.results[0];
vm.avatar = user.picture.large;
vm.name = user.name.first + " " + user.name.last;
vm.email = user.email;
})
}
Image for post
Image for post

Written by

Developer Android, Flutter

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store