Complete the code to listen for a click event on the button.
<template> <button [1]="handleClick">Click me</button> </template> <script setup> function handleClick() { alert('Button clicked!') } </script>
In Vue, @click is the shorthand to listen for click events on elements.
Complete the code to define the event handler function that updates the message.
<template> <button @click="[1]">Change Message</button> <p>{{ message }}</p> </template> <script setup> import { ref } from 'vue' const message = ref('Hello') function [1]() { message.value = 'You clicked!' } </script>
The function name used in the template and script must match. Here, handleClick is the correct handler name.
Fix the error in the event handler to correctly update the count.
<template> <button @click="increment">Clicked {{ count }} times</button> </template> <script setup> import { ref } from 'vue' const count = ref(0) function increment() { count[1] += 1 } </script>
In Vue, to update a reactive ref value, you must use .value.
Fill both blanks to create a reactive input that updates the message on input event.
<template> <input type="text" [1]="message" [2]="updateMessage" /> <p>{{ message }}</p> </template> <script setup> import { ref } from 'vue' const message = ref('') function updateMessage(event) { message.value = event.target.value } </script>
v-bind instead of v-model for two-way binding.@click which does not trigger on typing.v-model binds the input value reactively, and @input listens for input events to trigger the update function.
Fill all three blanks to create a button that toggles a boolean and shows its state.
<template> <button [1]="toggle">Toggle</button> <p>State is: {{ [2] }}</p> </template> <script setup> import { ref } from 'vue' const [3] = ref(false) function toggle() { [3].value = ![3].value } </script>
The button listens for @click events. The reactive boolean is named isActive, which is shown in the template and toggled in the script.