SOURCE

console 命令行工具 X clear

                    
>
console
<!DOCTYPE html>
<html lang="en">

<head>
	<title>example methods 实例</title>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<script type="text/javascript" src="../assets/js/vue.js">
	</script>
</head>

<body>
	<h1>example methods 实例</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 type="text/javascript">
        var app = new Vue({
            el: '#app',
            data: {
                num: 1
            },
            methods: {
                add: function () {
                    this.num++;
                }
            }
        })

        app.$on("reduce", function () {
            this.num--;
        })

        app.$once("reduceOnce", function () {
            this.num--;
        })

        function reduce() {
            app.$emit("reduce");
        }

        function reduceOnce() {
            app.$emit("reduceOnce");
        }

        //关闭事件
        function off() {
            app.$off('reduce');
        }
    </script>
</body>

</html>

本项目引用的自定义外部资源