<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>example-3</title>
    <script src="../assets/js/vue.js"></script>
    <script src="../assets/js/jquery-3.1.0.min.js"></script>
</head>
<body>
    <h1>example-3</h1>
    <hr>
    <div id="app">
        {{num}}
        <p><button @click="add">add</button></p>
    </div>
    <p><button onclick="reduce()">reduce</button></p>
    <p><button onclick="reduceOnce()">reduceOnce</button></p>
    <p><button onclick="off()">off</button></p>
    <script>
        var app = new Vue({
            el: ‘#app‘,
            data() {
                return {
                    num: 1
                }
            },
            methods: {
                add() {
                    this.num++
                }
            },
        })
        app.$on(‘reduce‘, function () {
            console.log(‘执行了reduce方法‘);
            this.num--
        })
        app.$once(‘reduceOnce‘, function () {
            console.log(‘执行了一次的方法‘);
            this.num--
        })
        function reduce() {
            app.$emit(‘reduce‘)
        }
        function reduceOnce() {
            app.$emit(‘reduceOnce‘)
        }
        function off() {
            app.$off(‘reduce‘)
        }
    </script>
</body>
</html>