Complete the code to access the native event object in a Vue 3 component.
<template> <button @click="handleClick([1])">Click me</button> </template> <script setup> function handleClick(event) { console.log(event); } </script>
In Vue templates, the native event object is accessed using $event.
Complete the code to log the native event's type inside the handler.
<script setup>
function handleClick(event) {
console.log(event.[1]);
}
</script>The type property of the event object tells you the kind of event triggered, like 'click'.
Fix the error in the code to correctly prevent the default action using the native event object.
<template> <a href="#" @click="handleClick([1])">Link</a> </template> <script setup> function handleClick(event) { event.[1](); } </script>
To stop the browser's default action (like following a link), call event.preventDefault().
Fill both blanks to create a Vue 3 component that logs the native event's target tag name and prevents default action.
<template> <form @submit="handleSubmit([1])"> <button type="submit">Submit</button> </form> </template> <script setup> function handleSubmit(event) { event.[2](); console.log(event.target.tagName); } </script>
Use $event in the template to pass the native event object, and call preventDefault() to stop the form from submitting normally.
Fill all three blanks to create a Vue 3 component that listens for a keydown event, logs the key pressed, and prevents default behavior.
<template> <input @keydown="handleKeydown([1])" /> </template> <script setup> function handleKeydown(event) { event.[2](); console.log(event.[3]); } </script>
Pass the native event with $event, call preventDefault() to stop default key actions, and log the pressed key with event.key.