v

1. v-on绑定:on:click点击事件,再触发方法里面的add()或del()

2. 详情查看官方文档:https://cn.vuejs.org/v2/api/#v-on

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 
 4 <head>
 5     <meta charset="UTF-8">
 6     <meta name="viewport" content="width=device-width, initial-scale=1.0">
 7     <meta http-equiv="X-UA-Compatible" content="ie=edge">
 8     <title>Document</title>
 9     <!-- Step1.对于vue,可以用cdn -->
10     <script src="https://cdn.bootcss.com/vue/2.5.17-beta.0/vue.min.js"></script>
11     <style>
12         #app div{
13             padding: 2%;
14             margin-bottom: 1%;
15             border-bottom: 1px solid #ddd;
16             background-color: blanchedalmond;
17         }
18     </style>
19 </head>
20 
21 <body>
22 
23 
24     <div id="app">
25         <div>皮卡丘要嗑{{count}}瓶药</div>
26         <button v-on:click="add"></button>
27         <button v-on:click="del"></button>
28     </div>
29 
30     <script type="text/javascript">
31         var app = new Vue({
32             el: '#app',
33             // 初始化数据
34             data: {
35                 count: 1
36             },
37             // 方法.
38             methods: {
39                 add() {
40                     this.count++;
41                 },
42                 del() {
43                     this.count--;
44                 }
45             }
46         })
47     </script>
48 </body>
49 
50 </html>
原文地址:https://www.cnblogs.com/cisum/p/9614722.html