方式一:默认获取
不填写时,默认第一个参数就是 event 对象。
<template>
<div>
<button @click="onClick">点击</button>
</div>
</template>
<script>
export default {
methods: {
onClick(e) {
(e);
}
}
}
</script>
方式二:$event
特殊变量 $event。 内联处理器中的方法 和 API 指令 v-on 中都有介绍。
必须是 $event 的写法,该参数位置可随意,也可放在第一个。
<template>
<div>
<button @click="onClick('hello', $event)">点击</button>
<!-- <button @click="onClick($event, 'hello')">点击</button> -->
</div>
</template>
<script>
export default {
methods: {
onClick(str, e) {
(str, e);
}
}
}
</script>