In Vue 3, $event
event objects can be accessed using . But in your code example, you can't $event
get the event object directly through e
because you didn't explicitly pass it as a parameter.
To get the event object e
, you can use inline functions in JavaScript to pass additional parameters. As follows:
<template>
<input type="file" @change="(e) => uploadImage(e, item, index)" />
</template>
<script>
export default {
methods: {
uploadImage(event, item, index) {
// 在这里访问事件对象 event
console.log(event);
}
}
}
</script>
In this example, we use the inline function (e) => uploadImage(e, item, index)
for binding @change
the event and e
pass the event object as the first parameter to uploadImage
the method. In this way, the event object can be accessed in the method and printed out in the console for verification.