<script>
export default {
data() {
return {
counter: 0,
};
},
methods:{
addCounter:function (number){
this.counter+=number
}
}
};
</script>
<template>
<div>
<!-- 绑定事件,js -->
<h2 @click="counter++">{{counter}}</h2>
<!--绑定事件,methods,没有传递参数 -->
<h2 @click="addCounter">{{counter}}</h2>
<!--绑定事件,methods,传递参数 -->
<h2 @click="addCounter(2)">{{counter}}</h2>
</div>
</template>
<style>
</style>
发表回复