//App.vue <template> <div id="app"> <!-- <img src="./assets/logo.png"> --> <!-- <router-view/> --> <div class="num"> <button @click="sub">-</button> <span>{{num}}</span> <button @click="add">+</button> </div> </div> </template> <script> export default { name: 'App', data:()=>{ return{ num:0 } }, methods: { add:function(){ if(this.num<10){ this.num++ }else{ alert('已经最大了') } }, sub:function(){ if(this.num>0){ this.num-- }else{ alert('已经最小了') } } } } </script> <style> #app { font-family: 'Avenir', Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-align: center; color: #2c3e50; margin-top: 60px; } .num button{ 50px; height: 25px; color: red; padding: 0; } .num span{ display: inline-block; 44px; height: 19px; border: 3px solid #ccc } </style>