Complete the code to call the method handleClick when the button is clicked.
<template> <button @click="[1]">Click me</button> </template> <script setup> function handleClick() { alert('Button clicked!') } </script>
In Vue, to use a method as an event handler, you pass the method name without parentheses. Using handleClick calls the method when the event happens.
Complete the inline handler to show an alert with 'Hello!' when the button is clicked.
<template> <button @click="[1]">Say Hello</button> </template>
alert without parentheses does not show the alert.Inline handlers can contain JavaScript expressions. Here, alert('Hello!') runs when the button is clicked.
Fix the error in the method handler to prevent the method from running immediately.
<template> <button @click="[1]">Submit</button> </template> <script setup> function submitForm() { console.log('Form submitted') } </script>
Using submitForm() calls the method immediately. To run it on click, use submitForm without parentheses.
Fill both blanks to create a method handler that passes the event object to handleInput.
<template> <input @input="[1]($event)" /> </template> <script setup> function handleInput([2]) { console.log([2].target.value) } </script>
The method handleInput is called with the event object event. The parameter name and usage must match.
Fill all three blanks to create an inline handler that calls updateCount with the new value from the event.
<template> <input @input="[1] = Number([2].target.value); [3]([1])" /> </template> <script setup> import { ref } from 'vue' const count = ref(0) function updateCount(value) { count.value = value } </script>
count instead of count.value.The inline handler updates count.value with the number from $event.target.value and calls updateCount with the new value.