-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstep15_AppReview.html
More file actions
168 lines (147 loc) · 5.16 KB
/
step15_AppReview.html
File metadata and controls
168 lines (147 loc) · 5.16 KB
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
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
box-sizing: border-box;
}
ul {
margin: 0;
padding: 0;
}
ul li {
cursor: pointer;
position: relative;
padding: 8px 8px 8px 40px;
background: #eee;
font-size: 14px;
}
ul li:hover {
background: #ddd;
}
/* li class='checked' 인 경우에 line 표기 */
ul li.checked {
background: #BBB;
color: #fff;
text-decoration: line-through;
}
.close {
position: absolute;
right: 0;
top: 0;
padding: 12px 16px 12px 16px
}
.close:hover {
background-color: #f44336;
color: white;
}
.header {
background-color: rgb(30, 206, 191);
padding: 30px 30px;
color: yellow;
text-align: center;
}
.header:after {
content: "";
display: table;
clear: both;
}
.input {
border: none;
width: 75%;
height: 35px;
padding: 10px;
float: left;
font-size: 16px;
}
.addbutton {
padding: 10px;
width: 25%;
height: 35px;
background: #d9d9d9;
color: #555;
float: left;
text-align: center;
font-size: 13px;
cursor: pointer;
}
.addbutton:hover {
background-color: #bbb;
}
.completed {
text-decoration: none;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="languagelistapp">
<div id="header" class="header">
<h2>Language List</h2>
<input class="input" type="text" v-model.trim="language"
placeholder="언어 입력 후 엔터" v-on:keyup.enter="addlanguage">
<span class="addbutton" v-on:click="addlanguage">추 가</span>
</div>
<ul id="languagelist">
<li v-for="lang in languagelist" v-bind:class="checked(lang.lang)" v-on:click="langToggle(lang.id)">
<span>{{ lang.language }}</span>
<span v-if="lang.lang"> (학습완료)</span>
<span class="close" v-on:click.stop="deletelanguage(lang.id)">×</span>
</li>
</ul>
</div>
<script type="text/javascript">
var vm = new Vue({
el: "#languagelistapp",
data: {
language: "",
languagelist: [
{ id: 1, language: "Python", lang: false },
{ id: 2, language: "Java", lang: true }, //lang=true인 경우 학습 완료 의미
{ id: 3, language: "JavaScript", lang: false },
{ id: 4, language: "SQL", lang: false }
]
},
methods: {
/* languagelist 데이터 속성에서 lang 속성이 true인 경우 checked 클래스를 적용 여부를 결정하는 기능 */
checked: function (lang) { //학습완료에 대한 체크 의미
if (lang) {
return { checked: true }
}else{
return { checked: false };
}
},
//추가 버튼을 클릭하거나 입력 필드에서엔터키를 눌렀을 때 할 일을 목록에서 추가하는 기능
//v-on:keyup.enter="addlanguage" : enter 키 입력시 호출되는 메소드
addlanguage: function (e) {
if (this.language !== "") {
this.languagelist.push({ id: new Date().getTime(), language: this.language, lang: false });
this.language = "";
}
},
//할 일 목록 오른쪽 상단의 x 를 클릭하면 목록에서 삭제
//삭제를 위해서 배열의 splice 메소드 사용
deletelanguage: function (id) {
var index = this.languagelist.findIndex(function (item) {
return item.id === id;
});
this.languagelist.splice(index, 1);
},
//list에서 선택된 id값과 배열의 id값 비교
langToggle: function (id) {
//https://www.w3schools.com/jsref/jsref_findindex.asp
//findIndex() : 배열 내의 첫번째 index 검색
var index = this.languagelist.findIndex(function (item) {
return item.id === id;
});
//true <-> false
this.languagelist[index].lang = !this.languagelist[index].lang;
}
}
})
</script>
</body>
</html>