1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Vue指令之v-on</title> </head> <body> <div id="app"> <h3> 计数器 : {{ counter }}</h3> <button v-on:click="count(1)">增加+1</button> <button @click="count(-1)">减少-1</button> <button @click="count(null, $event)" id="initBtn">清零=0</button> </div> </body> <script src="js/vue.js" type="text/javascript"></script> <script type="text/javascript"> var vm = new Vue({ el: "#app", data: { counter: 0 }, methods: { count: function(num, e) { if (e && e.target.id == "initBtn") { this.counter = 0 return } this.counter += num; } } }) </script> </html>
|