Consider a Vue component with a button that should increase a counter when clicked. What will be the counter value after clicking the button once?
<template> <button @click="increment">Click me</button> <p>Count: {{ count }}</p> </template> <script setup> import { ref } from 'vue' const count = ref(0) function increment() { count.value++ } </script>
Check how the event handler is connected to the button click.
When the event handler is correctly bound using @click="increment", clicking the button calls the increment function, increasing the count by 1.
Given a Vue component that toggles a boolean value on button clicks, what will be the displayed text after clicking the button three times?
<template> <button @click="toggle">Toggle</button> <p>{{ isActive ? 'Active' : 'Inactive' }}</p> </template> <script setup> import { ref } from 'vue' const isActive = ref(false) function toggle() { isActive.value = !isActive.value } </script>
Count how many times the boolean flips after each click.
The initial value is false ('Inactive'). Each click flips the value. After three clicks (odd number), the value is true, so the text shows 'Active'.
Identify the code snippet that will cause a syntax error when binding a click event in Vue.
Check the quotes around the event handler expression.
In Vue templates, event handler expressions must be enclosed in quotes. Option C lacks quotes, causing a syntax error.
Examine the code below. Why does clicking the button not update the displayed message?
<template> <button @click="changeMessage">Change</button> <p>{{ message }}</p> </template> <script setup> import { ref } from 'vue' let message = 'Hello' function changeMessage() { message = 'Goodbye' } </script>
Check how the message variable is declared and updated.
The variable 'message' is a plain string, not reactive. Vue cannot detect changes to it, so the UI does not update.
Choose the best explanation for why event handling is essential in Vue apps.
Think about what happens when a user clicks a button or types in a form.
Event handling connects user actions to code that updates the app state and UI, making the app interactive and responsive.