效果图
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/42b83396ad8a8164a4d855828491b384.gif#pic_center)
代码
<!DOCTYPE html>
<html lang="zh">
<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>
<script src="../lib/vue.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="../lib/bootstrap/css/bootstrap.css"/>
<style type="text/css">
.con-top{
margin-top: 10px;
}
</style>
</head>
<body>
<div id="app">
<div class="container">
<div class="row">
<div class="con-top">
<input type="text" class="form-control" v-model="n1" @keyup="calc" />
<select v-model="opt" class="btn btn-primary">
<option value ="+">+</option>
<option value ="-">-</option>
<option value ="*">*</option>
<option value ="/">/</option>
</select>
//@keyup文本框数据监听改变
<input type="text" class="form-control" v-model="n2" @keyup="calc" />
<input type="button" value="=" @click="calc" class="btn btn-primary" />
<input type="text" class="form-control" v-model="result" />
<input type="button" value="清零" class="btn btn-primary" @click="zero()" />
</div>
</div>
</div>
</div>
<script type="text/javascript">
var vm = new Vue({
el:'#app',
data:{
n1:0,
n2:0,
result:0,
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;
}
},
zero(){
this.n1 = this.n2 = this.result = 0,
this.opt = '+'
}
}
})
</script>
</body>
</html>