<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>计算</title>
    <script src="https://cdn.bootcss.com/vue/2.4.2/vue.js"></script>
</head>
<body>
    <div id="jisuan">
        <input type="number" v-model="input1"/>
        <select v-model="selected">
            <option value="0">+</option>
            <option value="1">-</option>
            <option value="2">*</option>
            <option value="3">/</option>
            <option value="4">%</option>
        </select>
        <input type="number" v-model="input2"/>
        <button @click="suan()">计算</button>
        <span>{{ resulted }}</span>
    </div>
</body>
</html>
<script type="text/javascript">
    var vm=new Vue({
        el:'#jisuan',
        data:{
            input1:'',
            input2:'',
            selected:'',
            resulted:'',
        },
        methods:{
            suan:function () {
                this.resulted=0;
                if (this.selected=='0'){
                    /*字符串变数字剪0*/
                    this.resulted=(this.input1-0)+(this.input2-0);
                }
                if (this.selected=='1'){
                    this.resulted=(this.input1-0)-(this.input2-0);
                }
                if (this.selected=='2'){
                    this.resulted=(this.input1-0)*(this.input2-0);
                }
                if (this.selected=='3'){
                    this.resulted=(this.input1-0)/(this.input2-0);
                }
                if (this.selected=='4'){
                    this.resulted=(this.input1-0)%(this.input2-0);
                }
            }
        }
    })
</script>

 

Logo

前往低代码交流专区

更多推荐