-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapod-api.html
51 lines (46 loc) · 1.48 KB
/
apod-api.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!DOCTYPE html>
<head>
<style>
[v-cloak] {
display: none;
}
</style>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
</head>
<body>
<div id='app'>
<div class='container'>
<h2 class='display-4 mt-5'>{{imgTitle}}</h2>
<img class='img-fluid my-4' :src='imgUrl' :title='imgTitle'/>
{{description}}
</div>
</div>
</body>
<script src='https://cdn.jsdelivr.net/npm/vue/dist/vue.js'></script>
<script src='https://unpkg.com/axios/dist/axios.min.js'></script>
<script>
var vm = new Vue({
el: '#app',
data: {
imgUrl: '',
imgTitle: '',
description: '',
},
created: function () {
this.fetchApod();
},
methods: {
fetchApod: function () {
var apiKey = 'h0k3AcqCkTZRwKjR6Hi6ep1LFGoQ7niMqoqAG4UH';
var url = 'https://api.nasa.gov/planetary/apod?api_key=' + apiKey;
axios.get(url)
.then(function (res) {
console.log(res);
vm.imgUrl = res.data.url;
vm.imgTitle = res.data.title;
vm.description = res.data.explanation;
})
}
}
});
</script>