-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvueListApi.html
147 lines (130 loc) · 4.49 KB
/
vueListApi.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<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>vueListApi</title>
<style>
#app {
margin: 0 auto;
width: 800px;
}
#app .title {
padding: 20px 0 0px;
font-size: 30px;
text-align: center;
}
#app #table {
width: 100%;
}
#app #table th {
border-bottom: 2px solid black;
text-align: center;
}
#app #table td {
padding: 5px 10px;
border-bottom: 1px dashed black;
text-align: left;
}
.paging {
text-align: center;
}
.paging #pagination {
padding: 0;
list-style: none;
}
.paging #pagination li {
display: inline-block;
padding: 10px;
list-style: none;
}
.paging #pagination > li.active,
.paging #pagination li.active {
background: sandybrown;
}
</style>
</head>
<body>
<div id="app">
<h2 class="title">Table List</h2>
<!-- list -->
<table id="table">
<thead>
<tr>
<th>타이틀</th>
<th>내용</th>
</tr>
</thead>
<!-- 익스플로러에서 안보임 ㅠㅠ -->
<!-- <tbody is="post-item"
v-for="post in posts"
v-bind:post="post"
v-bind:key="post.id"
>
</tbody> -->
<tbody>
<tr v-for="post in posts">
<td><strong>{{post.title}}</strong></td>
<td>{{post.body}}</td>
</tr>
</tbody>
</table>
<!-- // list -->
<!-- Pagination -->
<section class="paging">
<ul id="pagination"></ul>
</section>
<!-- // Pagination -->
</div>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="https://unpkg.com/[email protected]"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lodash.min.js"></script>
<script src="http://pagination.js.org/dist/2.1.4/pagination.js"></script>
<script>
/* 익스플로러에서 안보임 ㅠㅠ 이걸 사용하면 랜딩 시 {{post.title}} << 안보이게 해줌
Vue.component('post-item', {
props: ['post'],
template: `
<tr>
<td><strong>{{post.title}}</strong></td>
<td>{{post.body}}</td>
</tr>
`
})
*/
var vm = new Vue({
el: '#app',
data: {
posts: []
},
mounted: function () {
var _this = this;
$.ajax({
url: 'https://jsonplaceholder.typicode.com/posts', // post api
//url: './posts.json', // (추가: IE9에서는 위 url이 안먹힘 페이지를 posts.json으로 다운 받아서 연결시켜주면 IE9에서도 보임)
method: 'GET',
success: function (data) {
_this.posts = _.orderBy(data, ['title', 'body'], ['asc', 'asc']); // 1,타이틀, 2.내용 순으로 순차정렬
$('#pagination').pagination({
dataSource: _this.posts,
pageSize: 4,
pageRange: 2,
showPrevious: true,
showNext: true,
showPageNumbers: true,
showBeginingOnOmit : false,
//pageNumber: 3,
callback: function(data, pagination) {
_this.posts = data;
}
})
},
error: function (error) {
console.log("errpr : " + error);
}
});
}
});
</script>
</body>
</html>