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>
  • 相关阅读:
    WEB环境安装步骤v1.2
    将m3u8格式转成mp4格式
    MySQL简介及安装v0.1
    使用脚本pull阿里云的k8s镜像并更改标签
    常用脚本
    常用命令
    记录一下环境变量IFS特定场景使用技巧
    hp-unix创建和更改LV
    HP-UNIX常用命令
    Linux集群搭建
  • 原文地址:https://www.cnblogs.com/tiandlsd001/p/15250540.html
Copyright © 2011-2022 走看看