<!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>计算器</title>
</head>
<body>
<div id="app">
<input type="text" v-model="num1">
<select name="opt" id="" v-model="opt">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="text" v-model="num2">
<input type="button" value="=" v-on:click="cal">
<input type="text" v-model="result">
</div>
<script src="../lib/vue-2.4.0.js"></script>
<script>
var vm=new Vue({
el:"#app",
data:{
num1:0,
num2:0,
result:0,
opt:"+"
},
methods:{
cal(){
switch(this.opt){
case "+":this.result=parseInt(this.num1)+parseInt(this.num2);
break;
case "-":this.result=parseInt(this.num1)-parseInt(this.num2);
break;
case "*":this.result=parseInt(this.num1)*parseInt(this.num2);
break;
case "/":this.result=parseInt(this.num1)/parseInt(this.num2);
break;
}
}
}
});
</script>
</body>
</html>
网友评论