Challenge - 5 Problems
Vue Props & Events Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate1:30remaining
What is the rendered output when passing props?
Consider a Vue 3 component that receives a
message prop and displays it inside a paragraph. What will be the rendered output if the prop message is set to 'Hello Vue'?Vue
<template>
<p>{{ message }}</p>
</template>
<script setup>
const props = defineProps({
message: String
})
</script>Attempts:
2 left
💡 Hint
Remember that props are reactive and their values are displayed, not the variable name.
✗ Incorrect
The component receives the prop 'message' with value 'Hello Vue'. The template renders the value of message inside the paragraph, so the output is
Hello Vue
.❓ state_output
intermediate1:30remaining
What event is emitted and what is the payload?
A Vue 3 component emits an event named
update with a payload of 42 when a button is clicked. What will be the emitted event and payload after clicking the button once?Vue
<template> <button @click="$emit('update', 42)">Click me</button> </template> <script setup> // no additional script needed </script>
Attempts:
2 left
💡 Hint
Check the event name and the argument passed to $emit.
✗ Incorrect
The button click triggers $emit with event name 'update' and payload 42, so the emitted event is 'update' with payload 42.
🔧 Debug
advanced2:00remaining
Why does the event emit with a warning?
A Vue 3 component tries to emit an event named
submit on button click, but a console warning is shown in development. What is the likely cause?Vue
<template> <button @click="$emit('submit')">Submit</button> </template> <script setup> // no emits option declared </script>
Attempts:
2 left
💡 Hint
Vue 3 requires declaring emitted events explicitly in some cases.
✗ Incorrect
In Vue 3 with