效果图
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/3e9d2873059b1956a34f8e52d37d4e7a.png)
代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- 引入样式 -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<title>简易计算器</title>
</head>
<style>
.el-input {
max-width: 100px;
max-height: 5px;
}
</style>
<body>
<div id="app">
<!-- 第一个参数输入位置 -->
<el-input v-model="firstArg"></el-input>
<!-- 选择运算方式 -->
<el-select v-model="opt">
<el-option value="+">+</el-option>
<el-option value="-">-</el-option>
<el-option value="*">*</el-option>
<el-option value="/">/</el-option>
</el-select>
<!-- 第二个参数输入位置 -->
<el-input v-model="lastArg"></el-input>
<!-- 等于符号 -->
<el-button @click='cal' type='primary'>=</el-button>
<!-- 结果显示 -->
<el-input v-model="res"></el-input>
</div>
<script src="./js/vue.js"></script>
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>
const vm = new Vue({
el: '#app',
data: {
res: '',
firstArg: '',
lastArg: '',
opt: '+'
},
methods: {
cal: function() {
if (this.firstArg != null && this.lastArg != null) {
switch (this.opt) {
case '+':
this.res = parseInt(this.firstArg) + parseInt(this.lastArg);
break;
case '-':
this.res = parseInt(this.firstArg) - parseInt(this.lastArg);
break;
case '*':
this.res = parseInt(this.firstArg) * parseInt(this.lastArg);
break;
case '/':
this.res = parseInt(this.firstArg) / parseInt(this.lastArg);
break;
}
}
}
}
})
</script>
</body>
</html>