Challenge - 5 Problems
Vue Event Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What happens when clicking the button?
Consider this Vue component using
v-on to handle a click event. What will be the displayed output after clicking the button once?Vue
<template> <button v-on: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>
Attempts:
2 left
💡 Hint
Remember that
v-on:click calls the increment function which increases the count.✗ Incorrect
The
increment function increases the reactive count by 1 on each click. The paragraph updates to show the new count.📝 Syntax
intermediate1:30remaining
Which option correctly binds a click event using
v-on shorthand?In Vue, which of these options correctly uses the shorthand for
v-on:click to call the submitForm method?Attempts:
2 left
💡 Hint
The shorthand for
v-on:click is @click.✗ Incorrect
Option D uses the correct shorthand syntax
@click. The others have syntax errors or invalid attribute names.🔧 Debug
advanced2:30remaining
Why does this event handler not work as expected?
Given this Vue component, clicking the button does not update the message. What is the cause?
Vue
<template> <button v-on:click="changeMessage">Change</button> <p>{{ message }}</p> </template> <script setup> import { ref } from 'vue' const message = ref('Hello') function changeMessage() { message.value = 'Goodbye' } </script>
Attempts:
2 left
💡 Hint
Check if the variable used in the template is reactive.
✗ Incorrect
In Vue, variables must be reactive (e.g., using
ref) to update the template when changed. Here, 'message' is a plain variable.❓ state_output
advanced2:00remaining
What is the value of
count after clicking the button twice?Analyze this Vue component. What will be the value of
count after clicking the button two times?Vue
<template> <button v-on:click="increment">Add</button> <p>{{ count }}</p> </template> <script setup> import { ref } from 'vue' const count = ref(0) function increment() { count.value += 2 } </script>
Attempts:
2 left
💡 Hint
Each click adds 2 to the count.
✗ Incorrect
The
increment function adds 2 to count.value each time the button is clicked. After two clicks, count is 4.🧠 Conceptual
expert3:00remaining
Which option correctly prevents the default form submission using
v-on?You want to prevent the default form submission when clicking the submit button in Vue. Which option correctly uses
v-on modifiers to do this?Vue
<template> <form @submit.prevent="handleSubmit"> <button type="submit">Submit</button> </form> </template> <script setup> function handleSubmit() { alert('Form submitted') } </script>
Attempts:
2 left
💡 Hint
Use the modifier that stops the default browser action.
✗ Incorrect
The
.prevent modifier stops the default form submission. Other modifiers do different things: .stop stops event propagation, .capture changes event phase, .once runs handler once.