vue3中的v-on指令怎么让里面的函数获取到event
在Vue3中,可以通过使用特殊变量$event来获取事件对象,例如:
<template>
<button v-on:click="handleClick">Click me</button>
</template>
<script>
export default {
methods: {
handleClick(event) {
console.log(event) // undefined
console.log($event) // MouseEvent { ... }
}
}
}
</script>
在上面的示例中,传递给handleClick方法的event参数是undefined,但是可以使用$event变量来获取事件对象。
原文地址: https://www.cveoy.top/t/topic/hlUf 著作权归作者所有。请勿转载和采集!