利用v-model双向绑定
<div id="app">
<input type="text" v-model="value1">
<select v-model="value" name="" id="">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="text" v-model="value2">
<button @click="add">=</button>
<input type="text" v-model="value3">
</div>
let vm = new Vue({
el: '#app',
data: {
value1: '',
value2: '',
value3: '',
value: '+',
},
methods: {
add() {
if (this.value == '+') {
this.value3 = Number(this.value1) + Number(this.value2)
}
if (this.value == '-') {
this.value3 = Number(this.value1) - Number(this.value2)
}
if (this.value == '*') {
this.value3 = Number(this.value1) * Number(this.value2)
}
if (this.value == '/') {
this.value3 = Number(this.value1) / Number(this.value2)
}
// console.log(this.value);
}
}
})