简易计算器Vue
<div id="app">
<!-- 计算器 -->
<input type="text" v-model:value="value1">
<select v-model:value="option">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="text" v-model:value="value2">
<button @click="btn2">=</button>
<input type="text" v-model:value="value3">
</div>
<script>
let vm = new Vue({
el: "#app",
data: {
value1: '',
value2: '',
value3: '',
option: '+',
},
methods: {
btn1() {
console.log(this.value);
},
btn2() {
switch (this.option) {
case '+':
this.value3 = Number(this.value1) + Number(this.value2)
break;
case '-':
this.value3 = Number(this.value1) - Number(this.value2)
break;
case '*':
this.value3 = Number(this.value1) * Number(this.value2)
break;
case '/':
this.value3 = Number(this.value1) / Number(this.value2)
break;
default:
break;
}
}
},
})
</script>