vue中简易计算器

       
    <div id="app">
        <input type="text" v-model="n1">
        <select v-model="fuhao" >
            <option value="+">+</option>
            <option value="-">-</option>
            <option value="*">*</option>
            <option value="/">/</option>
        </select>
        <input type="text" v-model="n2" >

        <input type="button"   value="=" @click="deng">

        <input type="text"  v-model="reult" >
    </div>
    <script>
        var VM = new Vue({
            el:'#app',
            data:{
                n1:0,
                fuhao:"+",
                n2:0,
                reult:0,

            },
            methods:{
                deng() {
        // 计算的方法
          // 获取到 操作符
          // 获取到 n1 的值 和 n2 的值
          // 根据不同的操作符,计算这两个值的结果,最后,把结果赋值给 result 
switch(this.fuhao){
                        case '+':
                            this.reult  = parseInt(this.n1) + parseInt(this.n2)
                            break;
                        case '-':
                        this.reult  = parseInt(this.n1) - parseInt(this.n2)
                            break;
                            case '*':
                            this.reult  = parseInt(this.n1) * parseInt(this.n2)
                            break;
                        case '/':
                        this.reult  = parseInt(this.n1) / parseInt(this.n2)
                            break;

                    }
                }
            }
        });
    </script>

 



 







 

posted @ 2021-02-21 16:17  脑瓜疼不吃药药  阅读(76)  评论(0)    收藏  举报