1. <div id="app">
    2. <h2>当前计数:{{counter}}</h2>
    3. <!-- <button v-on:click='counter++'>+</button>
    4. <button v-on:click='counter--'>-</button> -->
    5. <button v-on:click='add'>+</button>
    6. <button @click='jian'>-</button>
    7. </div>
    8. <script>
    9. // const aa=20;
    10. const shuju = new Vue({
    11. el: '#app',
    12. data: {
    13. counter: 0,
    14. bb:30
    15. },
    16. methods:{//定义函数的
    17. add:function(){
    18. this.counter++;
    19. console.log("执行了add",this.bb);//如果在这里this.aa 结果提示未定义
    20. },
    21. jian:function(){
    22. this.counter--;
    23. console.log("执行了jian");
    24. }
    25. },//在vue里面可以定义 N个函数
    26. zidinyihanshu:function(){
    27. console.log('自定义函数');
    28. }
    29. })