Vue编写简易计算器

 时间:2024-11-02 21:31:12

1、引入vue.js<head> <meta charset="UTF-8"> <title>Vue简易计算器</title> <script src="../lib/vue.js"></script></head>

2、编老揉孟阼写基本HTML结构<div id="app"> <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="=" v-on:click="calc"> <input type="text" v-model="result"></div>

3、vue绑定对象<script> var app = new Vue({ el: &#泌驾台佐39;#app', data: { n1: '', n2: '', result: '', opt: '+' }, methods: { calc() { //判断操作符 switch (this.opt) { 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; } } } })</script>

4、效果显示

Vue编写简易计算器
  • intellij idea如何快速生成类的构造方法
  • IDEA界面如何设为中文?
  • netbeans怎么修改字体和字体大小
  • phpstudy无法启动mysql服务器怎么办?
  • Android Studio中如何为页面添加背景图片?
  • 热门搜索
    平安福终身寿险怎么样 完美生活许巍 穿越之换亲生活 八马茶叶怎么样 苹果5sid怎么注册 wf密码怎么修改 机智的医生生活 生活中的一个小镜头 如何学习会计 时沙之瓶配方怎么获得