zoukankan      html  css  js  c++  java
  • v-model 练习,简易计算器

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
    </head>
    <body>
        <div id="app">
            <input type="text" name="" id="" v-model:value="n1">
            <select name="" id="" v-model:value="opt">
                <option value="+">+</option>
                <option value="-">-</option>
                <option value="*">*</option>
                <option value="/">/</option>
            </select>
            <input type="text" v-model:value="n2">
            <input type="button" value="=" @click="calc">
            <input type="text" v-model="result"> 
        </div>
    </body>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>
         var app= new Vue({
            el:'#app',
            data:{
                n1:0,
                n2:0,
                result:0,
                opt:'+'

            },
            methods:{
                calc(){
                    // var codeStr='prseInt(this.n1)'+this.opt+'prseInt(this.n2)'
                    // this.result=eval(codeStr)
                    
                    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>
    </html>
  • 相关阅读:
    小球(总结sort和cmp函数、结构体排序)
    垃圾装袋(标记法)【标记思想】
    种树(标记思想)【贪心算法】
    PHP 配置文件
    最大前驱路径
    PHP代码片段
    PHP 中的Trait
    BootStrapTable 错误
    工作两周总结
    工作一周总结
  • 原文地址:https://www.cnblogs.com/tiandlsd001/p/15250540.html
Copyright © 2011-2022 走看看