<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div id="app"> <h2>当前计数:{{counter}}</h2> <!-- <button v-on:click="counter "> </button> --> <!-- <button v-on:click="counter--">-</button> --> <button v-on:click="add"> </button> <button @click="sub">-</button> </div> <script src="../js/vue.js"></script> <script> const app = new Vue({ el: '#app', data: { counter: 0 }, methods: { add: function () { console.log("add被执行"); this.counter ; }, sub: function () { console.log("sub被执行"); this.counter--; } } }) </script> </body> </html>,我来为大家讲解一下关于计数器简易图?跟着小编一起来看一看吧!

计数器简易图(案例计数器)

计数器简易图

案例:计数器

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div id="app"> <h2>当前计数:{{counter}}</h2> <!-- <button v-on:click="counter "> </button> --> <!-- <button v-on:click="counter--">-</button> --> <button v-on:click="add"> </button> <button @click="sub">-</button> </div> <script src="../js/vue.js"></script> <script> const app = new Vue({ el: '#app', data: { counter: 0 }, methods: { add: function () { console.log("add被执行"); this.counter ; }, sub: function () { console.log("sub被执行"); this.counter--; } } }) </script> </body> </html>

,