-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
535 lines (487 loc) · 19.5 KB
/
index.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>hello vue.js</title>
<style>
#list { width: 400px; border: 1px solid black; border-collapse: collapse; }
#list td, #list th { border: 1px solid black; text-align: center; }
#list > thead > tr { color: yellow; background-color: purple; }
#countrylist { width: 400px; border: 1px solid black; border-collapse: collapse; }
#countrylist td, #countrylist th { border: 1px solid black; text-align: center; }
#countrylist > thead > tr { color: yellow; background-color: purple; }
.divider { height: 2px; background-color: gray;}
</style>
<script src="https://unpkg.com/[email protected]/dist/vue.js"></script>
</head>
<body>
<div id="simple">
<!-- 기본 -->
<h2>{{message}}</h2>
<h2 v-text="message"></h2>
<h2 v-html="message"></h2>
<br>
<!-- 태그 -->
<h2>{{tag_message}}</h2>
<h2 v-text="tag_message"></h2>
<h2 v-html="tag_message"></h2>
<br>
<!-- v-bind -->
<input id="a" type="text" v-bind:value="bind_message" />
<br/>
<img v-bind:src="imagePath" />
<br/>
<!-- v-model -->
<input type="text" v-model="name" placeholder="이름을 입력하세요" />
<br/>
입력된 이름 : <h2 v-html="name"></h2>
</div>
<br>
<!-- v-model 심화 -->
<div id="simple1">
<div>
좋아하는 과일을 모두 골라주세요 :
</div>
<input type="checkbox" value="1" v-model="fruits" />사과,
<input type="checkbox" value="2" v-model="fruits" />키위,
<input type="checkbox" value="3" v-model="fruits" />포도,
<input type="checkbox" value="4" v-model="fruits" />수박,
<input type="checkbox" value="5" v-model="fruits" />참외
</div>
<div id="simple2">
선택한 과일들 : <span v-html="fruits"></span>
</div>
<br>
<!-- v-if -->
<div id="account">
예금액 : <input type="text" v-model="amount" />
<img v-if="amount < 0" src="http://sample.bmaster.kro.kr/img/error.png"
title="마이너스는 허용하지 않습니다"
style="width:15px; height:15px; vertical-align:middle" />
<br>
<br>
잔고 : <input type="text" v-model="balance" />
<br>
회원님의 등급 :
<span v-if="balance >= 1000000">Gold</span>
<span v-else-if="balance >= 500000">Silver</span>
<span v-else-if="balance >= 200000">Bronze</span>
<span v-else>Basic</span>
</div>
<br>
<!-- v-for를 이용한 table -->
<div id="example">
<table id="list">
<thead>
<tr>
<th>번호</th>
<th>이름</th>
<th>전화번호</th>
<th>주소</th>
</tr>
</thead>
<tbody id="contacts">
<tr v-for="contact in contacts">
<td>{{ contact.no }}</td>
<td>{{ contact.name }}</td>
<td>{{ contact.tel }}</td>
<td>{{ contact.addr }}</td>
</tr>
<!-- 배열 데이터에서 index 뽑아내기 -->
<tr v-for="(contact, index) in contacts">
<td>{{ index + 1 }}</td>
<td>{{ contact.no }}</td>
<td>{{ contact.name }}</td>
<td>{{ contact.tel }}</td>
<td>{{ contact.addr }}</td>
</tr>
<!-- v-for, v-if 적용 순서 (1.v-for 2. v-if) -->
<tr v-for="(contact, index) in contacts" v-if="contact.addr.indexOf('서울') > -1">
<td>{{ index + 1 }}</td>
<td>{{ contact.no }}</td>
<td>{{ contact.name }}</td>
<td>{{ contact.tel }}</td>
<td>{{ contact.addr }}</td>
</tr>
<!-- template이용 -->
<template v-for="(contact, index) in contacts">
<tr>
<td>{{ contact.no }}</td>
<td>{{ contact.name }}</td>
<td>{{ contact.tel }}</td>
<td>{{ contact.addr }}</td>
</tr>
<tr class="divider" v-if="index % 5===4">
<td colspan="4"></td>
</tr>
</template>
<!-- key속성 부여 -->
<template v-for="(contact, index) in contacts">
<tr :key="contact.no">
<td>{{ contact.no }}</td>
<td>{{ contact.name }}</td>
<td>{{ contact.tel }}</td>
<td>{{ contact.addr }}</td>
</tr>
<tr class="divider" v-if="index % 5===4">
<td colspan="4"></td>
</tr>
</template>
</tbody>
</table>
</div>
<br>
<!-- v-for를 이용한 options -->
<div id="options">
<select id="regions">
<option disabled="disabled" seleted>지역을 선택하세요</option>
<option v-for="(val, key) in regions" :value="key">{{ val }}</option>
<!-- 객체 데이터 index 추가 -->
<option v-for="(val, key, index) in regions" :value="key">{{ index + 1 }} :{{ val }}</option>
</select>
</div>
<br>
<!-- v-pre : 컴파일 없이 문자 그대로 출력 -->
<div id="pre">
v-pre : 컴파일 없이 문자 그대로 출력
<br>
v-pre : <span v-pre>{{ message }}</span>
</div>
<br>
<!-- v-once : 한번만 출력 -->
<div id="once">
v-once : 한번만 출력하여 데이터를 콘솔에서 변경해도 변경되지 않음
(초깃값 설정 후 변경되면 안될 때 사용)
<br>
<span v-once>{{ message }}</span>
</div>
<br>
<!-- count 계산형 속성 -->
<div id="count">
<input type="text" v-model="num" />
<br>
1부터 입력된 수까지의 합 : <span>{{ sum }}</span>
</div>
<br>
<!-- table 검색 필터 -->
<!--
computed만 사용할 경우 한글은 focus out이 되어야만 이벤트 실행
method를 이용하여 v-on 디렉티브를 사용할 경우 @input이벤트나 keyup이벤트 사용 가능
따라서, method를 이용할 경우 바로바로 이벤트가 실행된다ㄴ
-->
<div id="filter">
-- Computed --
<p>국가명: <input type="text" v-model="countryname" placeholder="국가명" /></p>
<table id="countrylist">
<thead>
<tr>
<td>번호</td>
<td>국가명</td>
<td>수도</td>
<td>지역</td>
</tr>
</thead>
<tbody id="contacts">
<tr v-for="c in filtered">
<td>{{ c.no }}</td>
<td>{{ c.name }}</td>
<td>{{ c.capital }}</td>
<td>{{ c.region }}</td>
</tr>
</tbody>
</table>
</div>
<br>
<div id="method">
-- Computed, Method, @input --
<p>국가명: <input type="text" :value="countryname" placeholder="국가명" @input="nameChanged"/></p>
<table id="countrylist">
<thead>
<tr>
<td>번호</td>
<td>국가명</td>
<td>수도</td>
<td>지역</td>
</tr>
</thead>
<tbody id="contacts">
<tr v-for="c in filtered">
<td>{{ c.no }}</td>
<td>{{ c.name }}</td>
<td>{{ c.capital }}</td>
<td>{{ c.region }}</td>
</tr>
</tbody>
</table>
</div>
<br>
<br>
<!-- getter/setter -->
<div id="getset">
설정된 금액을 get set을 컴퓨팅하여 세자리 마다 ','추가
<br>
금액 : <span>{{ amount }}원</span>
</div>
<br>
<!-- method -->
<div id="summethod">
<input type="text" v-model="num" />
<br>
1부터 입력된 수까지의 합 : <span>{{ sum() }}</span>
</div>
<br>
<!-- watch -->
<div id="sumWatch">
x : <input type="text" v-model="x">
<br>
y : <input type="text" v-model="y">
<br>
덧셈 결과 : {{ sum }}
</div>
<!-- computed -->
<div id="sumComputed">
x : <input type="text" v-model="x">
<br>
y : <input type="text" v-model="y">
<br>
덧셈 결과 : {{ sum }}
</div>
<script type="text/javascript">
var model = {
message: '첫 번째 Vue.js 앱입니다.'
, tag_message: '<i>첫 번째 Vue.js 앱입니다.</i>'
, bind_message: 'v-bind 디렉티브'
, imagePath: 'http://sample.bmaster.kro.kr/photos/61.jpg'
, name: ''
, fruits: []
};
var simple = new Vue({
el: '#simple'
, data: model
})
var simple1 = new Vue({
el: '#simple1'
, data: model
})
var simple2 = new Vue({
el: '#simple2'
, data: model
})
//////////////////////////
var accout = new Vue({
el: '#account'
, data: {
amount: 0
, balance: 0
}
})
////////////////////////////
var contacts_model = {
'pageno': 1
, 'pagesize': 10
, 'totalcount': 100
, 'contacts': [
{ 'no': 100, 'name': '설현', 'tel': '010-3456-7890', 'addr': '서울'}
, { 'no': 99, 'name': '설현1', 'tel': '010-3456-7899', 'addr': '대구'}
, { 'no': 98, 'name': '설현2', 'tel': '010-3456-7898', 'addr': '서울'}
, { 'no': 97, 'name': '설현3', 'tel': '010-3456-7897', 'addr': '서울'}
, { 'no': 96, 'name': '설현4', 'tel': '010-3456-7896', 'addr': '경기'}
, { 'no': 95, 'name': '설현5', 'tel': '010-3456-7895', 'addr': '대전'}
, { 'no': 94, 'name': '설현6', 'tel': '010-3456-7894', 'addr': '서울'}
, { 'no': 93, 'name': '설현7', 'tel': '010-3456-7893', 'addr': '부산'}
, { 'no': 92, 'name': '설현8', 'tel': '010-3456-7892', 'addr': '서울'}
, { 'no': 91, 'name': '설현9', 'tel': '010-3456-7891', 'addr': '세종'}
]
}
var list = new Vue({
el: '#example'
, data : contacts_model
})
//////////////////////////////////
var regions_model = {
'A': 'Asia'
, 'B': 'America'
, 'C': 'Europe'
, 'D': 'Africa'
, 'E': 'Oceania'
}
var options = new Vue({
el: '#options'
, data: {
regions : regions_model
}
})
///////////////////////////////////
var pre = new Vue({
el: '#pre'
, data: { message: 'Hello World!!' }
})
var once = new Vue({
el: '#once'
, data: { message: 'Hello World!!' }
})
///////////////////////////////////
var sum = new Vue({
el: '#count'
, data: { num: 0 }
, computed: {
sum: function() {
var n = Number(this.num);
if (Number.isNaN(n) || n < 1)
return 0;
return ((1+n) * n) / 2;
}
}
})
///////////////////////////////////
var country_model = {
countryname: ''
, countries: [
{ no: 1, name: '미국', capital: '워싱턴DC', region: 'america'}
, { no: 2, name: '프랑스', capital: '파리', region: 'europe'}
, { no: 3, name: '영국', capital: '런던', region: 'europe'}
, { no: 4, name: '중국', capital: '베이징', region: 'asia'}
, { no: 5, name: '태국', capital: '방콕', region: 'asia'}
, { no: 6, name: '모로코', capital: '라바트', region: 'africa'}
, { no: 7, name: '라오스', capital: '비엔티안', region: 'asia'}
, { no: 8, name: '베트남', capital: '하노이', region: 'asia'}
, { no: 9, name: '피치', capital: '수바', region: 'oceania'}
, { no: 10, name: '솔로몬 제도', capital: '호니아라', region: 'oceania'}
, { no: 11, name: '자메이카', capital: '킹스턴', region: 'america'}
, { no: 12, name: '나미비아', capital: '빈트후크', region: 'africa'}
, { no: 13, name: '동티모르', capital: '딜리', region: 'asia'}
, { no: 14, name: '멕시코', capital: '멕시코시티', region: 'america'}
, { no: 15, name: '베네수엘라', capital: '카라카스', region: 'america'}
, { no: 16, name: '서사모아', capital: '아피아', region: 'oceania'}
]
}
var filter_search = new Vue({
el: '#filter'
, data: country_model
, computed: {
filtered: function() {
var country_name = this.countryname.trim();
return this.countries.filter(function(item, index) {
if (item.name.indexOf(country_name) > -1) {
return true;
}
});
}
}
})
var method_search = new Vue({
el: '#method'
, data: country_model
, computed: {
filtered: function() {
var country_name = this.countryname.trim();
return this.countries.filter(function(item, index) {
if (item.name.indexOf(country_name) > -1) {
return true;
}
});
}
}
, methods: {
nameChanged: function(e) {
this.countryname = e.target.value;
}
}
})
/////////////////////////////
var getset = new Vue({
el: '#getset'
, data: {
amt: 1234567
}
, computed: {
amount: {
get: function() {
var s = new String(''+this.amt);
var result = '';
var num = 0;
for (var i=s.length-1; i>=0; i--) {
result = s[i] + result;
if (num%3 == 2 && i !== 0)
result = ',' + result;
num++;
}
return result;
}
, set: function(amt) {
if (typeof(amt) === 'string') {
var result = parseInt(amt.replace(/ ,/g, ''))
if (isNaN(result))
this.amt = 0;
else
this.amt = result;
} else if (typeof(amt) === 'number') {
this.amt = amt;
}
}
}
}
})
/////////////
var summethod = new Vue({
el: '#summethod'
, data: {
num: 0
}
, methods: {
sum: function() {
console.log(Date.now());
var n = Number(this.num);
if (Number.isNaN(n) || n < 1)
return 0;
return ((1 + n) * n) / 2;
}
}
})
//////////////
var sumWatch = new Vue({
el: '#sumWatch'
, data: {
x: 0
, y: 0
, sum: 0
}
, watch: {
x: function(val) {
console.log("## X값 변경");
var result = Number(val) + Number(this.y);
if (isNaN(result))
this.sum = 0;
else
this.sum = result;
}
, y: function(val) {
console.log("## Y값 변경");
var result = Number(this.x) + Number(val);
if (isNaN(result))
this.sum = 0;
else
this.sum = result;
}
}
})
//////////////
var sumComputed = new Vue({
el: '#sumComputed'
, data: {
x: 0
, y: 0
}
, computed: {
sum: function() {
var result = Number(this.x) + Number(this.y)
if(isNaN(result))
return 0;
else
return result;
}
}
})
</script>
</body>
</html>