<input type="text" v-model="n1">
<select name="" id="" v-model="opt">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="text" v-model="n2">
<input type="button" value="=" @click="calc">
<input type="text" v-model="result">
data () {
return {
msg: '猥琐发育,别浪~',
n1: 0,
n2: 0,
result: 0,
opt: '+'
}
}
calc: function(){
switch(this.calc){
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;
}
// var codeStr = 'parseInt(this.n1)'+ this.opt +' parseInt(this.n2)';
// this.result = eval(codeStr);
}