0
0
Vueframework~20 mins

Testing props and events in Vue - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Vue Props & Events Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
1: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>
A<p>Hello Vue</p>
B<p>{{ message }}</p>
C<p>message</p>
D<p></p>
Attempts:
2 left
💡 Hint
Remember that props are reactive and their values are displayed, not the variable name.
state_output
intermediate
1: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>
AEvent 'click' emitted with payload 42
BEvent 'update' emitted with payload 'Click me'
CEvent 'update' emitted with payload 42
DNo event emitted
Attempts:
2 left
💡 Hint
Check the event name and the argument passed to $emit.
🔧 Debug
advanced
2: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>
AThe parent component must listen with @click, not @submit
BThe event name 'submit' is reserved and cannot be emitted
CThe button click handler syntax is incorrect
DThe component must declare the event in the emits option to emit it properly
Attempts:
2 left
💡 Hint
Vue 3 requires declaring emitted events explicitly in some cases.