vue实现简易计算器_早秋_前端开发者

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>简易计算器</title>
    <script src="./lib/vue.js"></script>
</head>
<body>
<div id="app">
    <input type="text" v-model="num1">
    <select v-model="opt">
        <option value="+">+</option>
        <option value="-">-</option>
        <option value="*">*</option>
        <option value="/">/</option>
    </select>
    <input type="text" v-model="num2">
    <input type="button" value="=" @click="cal">
    <input type="text" v-model="result">
</div>
<script>
    var vm = new vue({
        el:"#app",
        data:{
            num1:0,
            num2:0,
            result:0,
            opt:"+"
        },
        methods:{
            cal(){
                switch (this.opt) {
                    case "+":
                        this.result = parseInt(this.num1) + parseInt(this.num2)
                        break;
                    case "-":
                        this.result = parseInt(this.num1) - parseInt(this.num2)
                        break;
                    case "*":
                        this.result = parseInt(this.num1) * parseInt(this.num2)
                        break;
                    case "/":
                        this.result = parseInt(this.num1) / parseInt(this.num2)
                        break;
                }
            }
        }
    })
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>简易计算器</title>
    <script src="./lib/vue.js"></script>
</head>
<body>
<div id="app">
    <input type="text" v-model="num1">
    <select v-model="opt">
        <option value="+">+</option>
        <option value="-">-</option>
        <option value="*">*</option>
        <option value="/">/</option>
    </select>
    <input type="text" v-model="num2">
    <input type="button" value="=" @click="cal">
    <input type="text" v-model="result">
</div>
<script>
    var vm = new vue({
        el:"#app",
        data:{
            num1:0,
            num2:0,
            result:0,
            opt:"+"
        },
        methods:{
            cal(){
                switch (this.opt) {
                    case "+":
                        this.result = parseInt(this.num1) + parseInt(this.num2)
                        break;
                    case "-":
                        this.result = parseInt(this.num1) - parseInt(this.num2)
                        break;
                    case "*":
                        this.result = parseInt(this.num1) * parseInt(this.num2)
                        break;
                    case "/":
                        this.result = parseInt(this.num1) / parseInt(this.num2)
                        break;
                }
            }
        }
    })
</script>
</body>
</html>

<!DOCTYPE html><html lang=”en”><head><meta charset=”UTF-8″><title></title><script src=”./lib/vue.js></script></head><body><div id=”app”><input type=”text” v-model=”num1″><select v-model=”opt”><option value=”+”></option><option value=”-“></option><option value=”*”></option><option value=”/”></option></select><input type=”text” v-model=”num2″><input type=”button” value=”=” @click=”cal”><input type=”text” v-model=”result”></div><script>var vm =new vue({
el:
#app,
data:{
num1:
0,
num2:
0,
result:
0,
opt:
+
},
methods:{
cal(){
switch (this.opt) {
case+:
this.result = parseInt(this.num1) + parseInt(this.num2)
break;
case:
this.result = parseInt(this.num1) parseInt(this.num2)
break;
case*:
this.result = parseInt(this.num1) * parseInt(this.num2)
break;
case/:
this.result = parseInt(this.num1) / parseInt(this.num2)
break;
}
}
}
})
</script></body></html>

 

» 本文来自:前端开发者 » 《vue实现简易计算器_早秋_前端开发者》
» 本文链接地址:https://www.rokub.com/73396.html
» 您也可以订阅本站:https://www.rokub.com
赞(0)
64K

评论 抢沙发

评论前必须登录!