vue-model 간이 계산기 구현
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Vue</title>
<script src="../lib/vue-2.4.0.js"></script>
</head>
<body>
<div id="app" >
<!-- -->
<input type="text" v-model='n1' placeholder="0">
<!-- -->
<select v-model='opt'>
<option value="+"> + </option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<!-- 2 -->
<input type="text" v-model='n2' placeholder="0">
<!-- -->
<input type="button" value='=' >
<!-- -->
<input type="text" v-model='result' placeholder="0">
<!-- -->
<input type="button" value=' ' @click='calc'>
<!-- -->
<input type="button" value=' ' @click='zero'>
</div>
<script>
var vm = new Vue({
el: '#app', // new
data: { //data el
n1: '',
n2:'',
result:'',
opt: '+'
},
methods:{
calc(){
// switch(this.opt){
// case '+':
// this.result = parseInt(this.n1) + parseInt(this.n2)
// break;
// case '-':
// this.result = parseInt(this.n1) - parseInt(this.n2)
// break;
// case '*':
// this.result = parseInt(this.n1) * parseInt(this.n2)
// break;
// case '/':
// this.result = parseInt(this.n1) / parseInt(this.n2)
// break;
// }
//
var codeStr = 'parseInt(this.n1) '+ this.opt +' parseInt(this.n2)'
this.result = eval(codeStr)
},
zero(){
this.n1 = '',
this.n2 = '',
this.result = '',
this.opt = '+'
}
}
})
</script>
</body>
</html>
계산기 관련 기술 기사는 테마를 클릭하십시오javascript 계산기 기능 요약 이상은 본문의 전체 내용입니다. 여러분의 학습에 도움이 되고 저희를 많이 응원해 주십시오.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Fastapi websocket 및 vue 3(Composition API)1부: FastAPI virtualenv 만들기(선택 사항) FastAPI 및 필요한 모든 것을 다음과 같이 설치하십시오. 생성main.py 파일 및 실행 - 브라우저에서 이 링크 열기http://127.0.0.1:...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.