<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <script src="vue.js" type="text/javascript" charset="utf-8"></script> </head> <div id="app"> <p>{{msg}}</p> <input type="text" name="" id="" value="" v-model="num1"/> <select v-model="calsymbol"> <option value ="+">+</option> <option value ="-">-</option> <option value ="*">*</option> <option value ="/">/</option> </select> <input type="text" name="" id="" value=""v-model="num2" /> <input type="button" name="" id="" value="=" @click="cal"/> <input type="text" name="" id="" value="" v-model="result"/> </div> <script type="text/javascript"> var vm=new Vue({ el:"#app", data:{ msg:"请输入你想计算的数字", num1:0, num2:0, result:0, calsymbol:'+' }, methods:{ cal(){ this.result=eval('parseInt(this.num1)'+this.calsymbol+'parseInt(this.num2)') } } }) </script> <body> </body> </html>

标签: none

添加新评论