본문 바로가기
study/Vue

[Vue] 28. 두 수의 합 구하기 (exam1.html )

by 금이패런츠 2022. 5. 30.
728x90
반응형

exam1.html

<!DOCTYPE html>
<!-- /vue1/src/main/webapp/20220530/exam1.html -->
<html>
<head>
<meta charset="UTF-8">
<title>두 수의 합 구하기</title>
<script type="text/javascript" src="https:unpkg.com/vue@2.5.16/dist/vue.js"></script>
</head>
<body>
<div id="example">
	x: <input type="text" v-model="x"><br>
	y: <input type="text" v-model="y"><br>
	덧샘결과 : <span>{{sum}}</span>
</div>
<script type="text/javascript">
	let vSum = new Vue ({
		el : "#example",
		data : {
			x:1, 
			y:3
		}, // 상단 모델 연결
		computed : { 
			// 더하기 기능
			sum : function(){
				let x = Number(this.x)
				let y = Number(this.y)
				if(Number.isNaN(x) || Number.isNaN(y)) return 0;
				return x + y ; 
			}
		}
	})
</script>
</body>
</html>
728x90
반응형