-
Notifications
You must be signed in to change notification settings - Fork 0
/
components.html
89 lines (73 loc) · 2.4 KB
/
components.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>VUE js V2 Componentes | Device 4 Code</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
</head>
<body>
<div id="main" class="container">
<div class="row">
<div class="col-sm-4">
<h1>Album</h1>
<common-list v-bind:lists="albums"></common-list>
</div>
<div class="col-sm-4">
<h1>Posts</h1>
<common-list v-bind:lists="posts"></common-list>
</div>
<div class="col-sm-4">
<h1>Todos</h1>
<common-list v-bind:lists="todos"></common-list>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.2/vue.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.min.js"></script>
<script type="text/javascript">
Vue.component('common-list',{
props : ['lists'],
template : `<ul class="list-group">
<li v-for="item in lists" class="list-group-item">
{{ item.title }}
</li>
</ul>`
});
var urlPosts = 'http://jsonplaceholder.typicode.com/posts';
var urlAlbums = 'http://jsonplaceholder.typicode.com/albums';
var urlTodos = 'http://jsonplaceholder.typicode.com/todos';
new Vue({
el: '#main',
created: function() {
this.getPosts(),
this.getAlbums(),
this.getTodos()
},
data: {
posts: [],
albums: [],
todos: [],
},
methods: {
getPosts: function() {
axios.get(urlPosts).then(response => {
this.posts = response.data
});
},
getAlbums: function() {
axios.get(urlAlbums).then(response => {
this.albums = response.data
});
},
getTodos: function() {
axios.get(urlTodos).then(response => {
this.todos = response.data
});
},
}
});
</script>
</body>
</html>