<body> <div id="app"> <button @click="add">+</button> <button @click="sub">-</button> <p> {{ num }} </p> </div> <script src='https://cdn.jsdelivr.net/npm/vue@2.6.12/dist/vue.js'></script> <script> const app = new Vue({ el: '#app', data: { num: 0, }, methods: { add() { // 用ES6函数增强写法 this.num++; }, sub() { this.num--; } } }) </script> </body>