先看代码:
<body>
<div id="box">
{
{count}}
<button @click="handleAdd1()">add1</button>
<button @click="handleAdd2">add2</button>
</div>
<script>
new Vue({
el: "#box",
data: {
count: 0,
},
methods: {
handleAdd1(){
this.count++
},
handleAdd2(evt) {
this.count++
console.log(evt)
},
}
})
</script>
</body>
结果:点击add1,count数量会增加;点击add2,count数量会增加,然后打印出evt的值见下图: