Props are custom attributes that allow a parent component to pass data down to a child component in Vue.
Click to reveal answer
beginner
How do you declare props in a Vue 3 component using the Composition API?
You declare props by defining a <code>props</code> option in the <code><script setup></code> block, for example: <pre>const props = defineProps({ title: String })</pre>
Click to reveal answer
intermediate
Why should props be treated as read-only inside child components?
Props are read-only to keep data flow predictable and avoid side effects. Changing props inside a child can cause bugs and breaks Vue's one-way data flow.
Click to reveal answer
beginner
How can you pass a string and a number from a parent to a child component using props?
In the parent template, use:
<ChildComponent title="Hello" count="5" />
For numbers, use binding:
<ChildComponent :count="5" />
Click to reveal answer
intermediate
What happens if a required prop is not passed to a child component in Vue?
Vue will warn in the console during development that a required prop is missing, helping catch errors early.
Click to reveal answer
How do you pass data from a parent to a child component in Vue?
AUsing slots
BUsing events
CUsing props
DUsing watchers
✗ Incorrect
Props are the way to send data from parent to child components in Vue.
In Vue 3 with <script setup>, how do you declare props?
AUsing computed()
BUsing defineProps()
CUsing data()
DUsing methods()
✗ Incorrect
The defineProps() function declares props in the <script setup> block.
What is the correct way to pass a number prop named 'age' with value 30?
A<code><Child :age="30" /></code>
B<code><Child age="30" /></code>
C<code><Child :age="'30'" /></code>
D<code><Child age=30 /></code>
✗ Incorrect
Using the colon (:) binds the number 30 as a number, not a string.
Can a child component modify the value of a prop it receives?
AOnly if using v-model
BYes, props can be changed freely
COnly if the prop is marked writable
DNo, props are read-only inside the child
✗ Incorrect
Props should be treated as read-only to maintain one-way data flow.
What will Vue do if a required prop is missing in development mode?
AShow a console warning
BThrow a runtime error
CIgnore silently
DAutomatically assign a default value
✗ Incorrect
Vue warns in the console to help developers catch missing required props.
Explain how props work in Vue to pass data from a parent to a child component.
Think about how a parent shares information with a child.
You got /4 concepts.
Describe how to declare and use props in a Vue 3 component using the <script setup> syntax.
Focus on the Composition API style.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of props in Vue components?
easy
A. To pass data from a parent component to a child component
B. To store local state inside a component
C. To handle user input events
D. To define methods inside a component
Solution
Step 1: Understand the role of props
Props are designed to send data from a parent component down to its child components.
Step 2: Differentiate props from other features
Local state stores data inside a component, events handle user actions, and methods define functions. Only props pass data downward.
Final Answer:
To pass data from a parent component to a child component -> Option A
Quick Check:
Props = Parent to Child Data [OK]
Hint: Props always send data from parent to child [OK]
Common Mistakes:
Confusing props with local state
Thinking props handle events
Assuming props define methods
2. Which of the following is the correct way to declare a prop named title in a Vue 3 child component using <script setup>?
easy
A. const props = defineProps({ title: String })
B. props: ['title']
C. export default { props: ['title'] }
D. const title = ref('')
Solution
Step 1: Identify Vue 3 <script setup> syntax
In Vue 3 with <script setup>, props are declared using defineProps().
Step 2: Match the correct syntax for prop declaration
const props = defineProps({ title: String }) correctly declares a prop named title of type String.
Final Answer:
const props = defineProps({ title: String }) -> Option A
A. Props must be declared as reactive refs to modify
B. The prop type Number is invalid in defineProps
C. Missing import of defineProps
D. Props are read-only and cannot be assigned new values
Solution
Step 1: Recall prop immutability
Props in Vue are read-only inside child components and cannot be directly modified.
Step 2: Identify the error in code
The code tries to assign a new value to props.count, which violates the read-only rule and causes an error.
Final Answer:
Props are read-only and cannot be assigned new values -> Option D
Quick Check:
Props cannot be changed inside child [OK]
Hint: Never assign new values to props inside child [OK]
Common Mistakes:
Trying to mutate props directly
Confusing props with reactive state
Ignoring Vue warnings about prop mutation
5. You want to pass a list of user names from a parent to a child component and display them. Which approach correctly passes and uses the prop in the child component using Vue 3 <script setup>?
Parent template:
<UserList :users="['Alice', 'Bob', 'Charlie']" />
Choose the correct child component code:
hard
A.
<script setup>
export default {
props: ['users']
}
</script>
<template>
<ul>
<li v-for="user in users" :key="user">{{ user }}</li>
</ul>
</template>
B.
<script setup>
const users = ref([])
</script>
<template>
<ul>
<li v-for="user in users" :key="user">{{ user }}</li>
</ul>
</template>