-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstep14_computedMethod.html
More file actions
86 lines (75 loc) · 2.52 KB
/
step14_computedMethod.html
File metadata and controls
86 lines (75 loc) · 2.52 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
<!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>
.score {
background-color: rgb(127, 255, 138);
border: solid 1px black;
}
.warning {
background-color: rgb(255, 0, 76);
color: purple;
}
.warnimage {
width: 18px;
height: 18px;
top: 5px;
position: relative;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<!-- 제공 start -->
<dl>
<dt>
<h3>계산형 속성(computed)을 이용하여 스타일(css) 적용 해 보기</h3>
</dt>
<dd>
1부터 5까지만 입력
</dd>
<dd>
5초과시 이미지가 활성 + red색으로 변환
</dd>
<br>
<div id="example">
<div>
<!-- input 요소에 score 속성 바인딩
input 요소에서 입력한 값은 score에 설정되고 info 계산형 속성이 바인딩
class 속성엔 warning 자동 추가
6이상 부터는 <input type="number" class="score warning"> 으로 변경
-->
<!-- ??? -->
score : <input type="number" class="score" v-model.number="score" v-bind:class="info" />
<img src="images/error.png" class="warnimage" v-show="info.warning" />
</div>
</div>
</dl>
<script type="text/javascript">
var vm = new Vue({
el: "#example",
data: {
score: 0 //input 요소에 양방향 바인딩되어 있음
},
//info 호출 및 활용은 어디서? input & img (info.warning 표기로 style 적용)
computed: {
info: function(){
if(this.score >=0 && this.score <= 5){
//정상 입력 화면 및 초록색
//waring : false인 경우 css 미적용을 의미
return{ waring : false}
}else{
//무효한 범위에 따라서 red
//warning : false인 경우 css 적용을 의미
return{warning : true}
}
}
}
});
console.log(vm.$data.score);
</script>
</body>
</html>