728x90
반응형
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>간단한 계산기 만들기</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<!--더하기, 빼기, 곱하기, 나누기 기능 넣기
input text 안에 숫자 두 개를 넣고 버튼을 누르면 아래 text로 결과가 표시되게 하기-->
<h1>간단한 계산기</h1>
<p>
<input v-model.number="firstNum">
<input v-model.number="secondNum">
</p>
<p>
<button v-on:click="add(firstNum, secondNum)">덧셈계산</button>
<button v-on:click="min(firstNum, secondNum)">뺄셈계산</button>
<button v-on:click="mul(firstNum, secondNum)">곱셈계산</button>
<button v-on:click="div(firstNum, secondNum)">나눗셈계산</button>
</p>
결과는 [{{ result }}] 입니다.
</div>
<script>
new Vue({
el : '#app',
data : {
firstNum : 0,
secondNum : 0,
result : 0
},
methods : {
add : function(fNum,sNum){
this.result = fNum + sNum;
},
min : function(fNum,sNum){
this.result = fNum - sNum;
},
mul : function(fNum,sNum){
this.result = fNum * sNum;
},
div : function(fNum,sNum){
this.result = fNum / sNum;
}
}
})
</script>
</body>
</html>
728x90
반응형