zoukankan      html  css  js  c++  java
  • Vue实现简易计算机

    Vue实现简易计算机

    1. html
    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <title>Vue实现自定义计算器</title>
        <!--    引进Css样式码   -->
        <link rel=stylesheet href="./d-1.css">
    </head>
    
    <body>
        <div id="app">
            <div id="app1">
            <input type="number" v-model.number="num1" />
            <select name="" id="" v-model.number="operator">
                <option value="0">+</option>
                <option value="1">-</option>
                <option value="2">*</option>
                <option value="3">/</option>
            </select>
            <input type="number" v-model.number="num2" />
            <button @click="cal">=</button>
            <strong>{{res}}</strong>
            </div>
        </div>
        <!--    需联网    -->
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js"></script>
        <!--    引进js代码    -->
        <script src="./d-1.js"></script>
    </body>
    
    </html>
    
    1. javascript
    
    const vm = new Vue({
        el: "#app",
        data() {
            return {
                num1: 0,
                num2: 0,
                operator: 0,
                res: 0
            }
        },
        methods: {
            cal() {
                switch (this.operator) {
                    case 0:
                        this.res = this.num1 + this.num2;
                        break;
                    case 1:
                        this.res = this.num1 - this.num2;
                        break;
                    case 2:
                        this.res = this.num1 * this.num2;
                        break;
                    case 3:
                        this.res = this.num1 / this.num2;
                        break;
                }
            }
        }
    });
    
    
    1. Css
    
    #app{
        100%;
       height: 80%;
       background-color: skyblue;
       position: absolute;
    }
    
    #app1{
       position: relative;
       top: 5%;
       left: 30%;
    }
    
    
  • 相关阅读:
    表单工具可以什么
    页面嵌套的方式展现报表
    EChars图类型
    SVG图类型
    JSP <c:import>和<jsp:include>区别【转】
    Servlet配置
    jsp的scope属性【转载】
    Cookie、Session【转载】
    page、request、session、application区别【转载】
    C++笔记------static 和 const 在类中用法
  • 原文地址:https://www.cnblogs.com/k-class/p/14058358.html
Copyright © 2011-2022 走看看