<!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>Document</title>
</head>
<body>
<div id="app">
<div>
<span>数值A</span>
<span><input type="text" name="" v-model='a'></span>
</div>
<div>
<span>请输入加减乘除</span>
<span><input type="text" name="" v-model='fh'></span>
</div>
<div>
<span>数值B</span>
<span><input type="text" name="" v-model='b'></span>
</div>
<div>
<button v-on:click='handle'>计算</button>
</div>
<div>
<span>计算结果:</span>
<span v-text='result'></span>
</div>
</div>
<script type="text/javascript" src="js/vue.js"></script>
<script type="text/javascript">
//Vue.config.keyCodes.aaa = 65
var vm = new Vue({
el: '#app',
data: {
a: '',
b: '',
fh: '',
result: ''
},
methods: {
handle: function(e) {
switch (this.fh) {
case '+':
this.result = parseInt(this.a) + parseInt(this.b);
break;
case '-':
this.result = parseInt(this.a) - parseInt(this.b);
break;
case '*':
this.result = parseInt(this.a) * parseInt(this.b);
break;
case '/':
this.result = parseInt(this.a) / parseInt(this.b);
break;
default:
this.result = '';
}
}
}
});
</script>
</body>
</html>
VUE简易版计算器
最新推荐文章于 2023-05-06 19:01:26 发布