【VUE】计数器模块

<!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>计数器</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <style>
        button {
            float: left;
            width: 50px;
            height: 25px;
        }
        
        span {
            float: left;
            width: 25px;
            height: 25px;
            font-size: 20px;
            text-align: center;
        }
    </style>
</head>

<body>
    <div id="app">
        <button value="+" @click="add">+</button>
        <span>{{num}}</span>
        <button value="-" @click="sub">-</button>
    </div>
    <script>
        var app = new Vue({
            el: "#app",
            data: {
                num: 1
            },
            methods: {
                add: function() {
                    this.num++;
                },
                sub: function() {
                    this.num--;
                }
            }
        })
    </script>
</body>

</html>
posted @ 2021-04-02 09:42  ice猫猫3  阅读(53)  评论(0编辑  收藏  举报