<div id="app">
<button type="button" @click="btn('123')">+</button>
<button type="button" @click="btn()">+</button>
<button type="button" @click="btn">+</button>
<button type="button" @click="btn($event,'333')">+</button>
<button type="button" @click="btn2($event)">+2</button>
</div>
<script src="vue.js"></script>
<script>
const app = new Vue({
el: "#app",
data() {
return {}
},
methods: {
/* btn(value) {
console.log(value);
} */
btn(e, value) {
console.log(e);
console.log(value);
},
btn2(e) {
console.log(e);
}
},
computed: {
}
})
/* 1.如需要传参 在页面中传的是实参 在methods中写的是形参.
2.如果在页面中没有写实参但是留有括号 在在methods中写了形参 会打印undefined
3.如果在页面中没有写实参也没有留有括号 在在methods中写了形参 会打印event
4.如果你想同时传事件和参数 在页面中那就要第一参数写$event,第二个是参数
5.如果你只传事件 那么在页面中可以完全不写括号 或者btn2($event)*/
</script>
v-on的参数传递
最新推荐文章于 2022-07-29 10:41:28 发布