zoukankan      html  css  js  c++  java
  • Vue 制作简易计算器

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>简易计算器</title>
    <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
    </head>
    <body>
    <div id="app">
      <input type="text" v-model="n1">
        <select 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" @click="calc1" value="=">
      <input type="text" v-model="result">
    </div>
    
    <script>
    var vm = new Vue({
      el: '#app',
      data: {
       n1:0,
       n2:0,
       opt: '+',
       result: 0,
      },
      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;
            }
        },
          calc1(){
          var codeStr = 'parseInt(this.n1) ' + this.opt + 'parseInt(this.n2)';
            this.result =eval(codeStr);
          }
    
      }
    })
    </script>
    </body>
    </html>
  • 相关阅读:
    Spring事务管理
    Spring中使用Hibernate
    tkinter学习笔记_04
    tkinter学习笔记_03
    tkinter学习笔记_02
    tkinter学习笔记_01
    tkinter模块常用参数(python3)
    单选框默认选中
    Tkinter & mysql 的登录框练习
    python爬虫-喜马拉雅_晚安妈妈睡前故事
  • 原文地址:https://www.cnblogs.com/f-rt/p/10065280.html
Copyright © 2011-2022 走看看