Bird
Raised Fist0
Vueframework~20 mins

Props for parent to child data in Vue - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Vue Props Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What will be displayed by the child component?
Given the parent passes a prop message to the child, what will the child render?
Vue
<template>
  <ChildComponent :message="parentMessage" />
</template>

<script setup>
import ChildComponent from './ChildComponent.vue'
import { ref } from 'vue'
const parentMessage = ref('Hello from parent')
</script>

<!-- ChildComponent.vue -->
<template>
  <p>{{ message }}</p>
</template>

<script setup>
const props = defineProps({
  message: String
})
</script>
AThe child displays nothing because props are not reactive
BThe child displays: {{ message }}
CThe child displays: Hello from parent
DThe child throws an error because message is not defined
Attempts:
2 left
💡 Hint
Remember that props passed from parent to child are reactive and accessible in the child template.
📝 Syntax
intermediate
1:30remaining
Which option correctly defines a required string prop in Vue 3?
You want to define a prop named title that must be a string and is required. Which code snippet is correct?
Aconst props = defineProps({ title: { type: String, required: true } })
Bconst props = defineProps({ title: { type: String, isRequired: true } })
Cconst props = defineProps({ title: { type: 'string', required: true } })
Dconst props = defineProps({ title: String, required: true })
Attempts:
2 left
💡 Hint
Check the correct syntax for prop validation in Vue 3's defineProps.
❓ state_output
advanced
2:00remaining
What is the output when the parent updates the prop?
If the parent changes the prop value after initial render, what will the child display?
Vue
<template>
  <ChildComponent :count="count" />
  <button @click="count++">Increment</button>
</template>

<script setup>
import { ref } from 'vue'
import ChildComponent from './ChildComponent.vue'
const count = ref(0)
</script>

<!-- ChildComponent.vue -->
<template>
  <p>Count is: {{ count }}</p>
</template>

<script setup>
const props = defineProps({ count: Number })
</script>
AThe child throws an error because props cannot change
BThe child shows the initial count value and does not update
CThe child shows undefined because count is not reactive
DThe child updates and shows the new count value each time the button is clicked
Attempts:
2 left
💡 Hint
Props are reactive in Vue and update the child when the parent changes them.
🔧 Debug
advanced
2:30remaining
Why does this child component fail to receive the prop?
The parent passes userName as a prop, but the child shows an empty string. What is the problem?
Vue
<!-- Parent.vue -->
<template>
  <ChildComponent user-name="Alice" />
</template>

<script setup>
import ChildComponent from './ChildComponent.vue'
</script>

<!-- ChildComponent.vue -->
<template>
  <p>User: {{ userName }}</p>
</template>

<script setup>
const props = defineProps({ userName: String })
</script>
AThe parent should bind the prop with a colon like <code>:userName="'Alice'"</code>
BThe child forgot to import the prop
CThe child must use <code>props.userName</code> instead of just <code>userName</code>
DThe parent uses kebab-case <code>user-name</code> but the child expects camelCase <code>userName</code> prop
Attempts:
2 left
💡 Hint
Check how static string props are passed in Vue templates.
🧠 Conceptual
expert
3:00remaining
What happens if a child tries to mutate a prop directly?
In Vue 3, if a child component tries to change a prop value directly, what will happen?
Vue
<template>
  <p>{{ count }}</p>
  <button @click="count++">Increase</button>
</template>

<script setup>
const props = defineProps({ count: Number })
</script>
AThe prop value changes and updates the parent automatically
BVue will warn in the console and the prop value will not change
CThe app crashes with a runtime error
DThe prop value changes locally but does not update the parent
Attempts:
2 left
💡 Hint
Props are meant to be read-only inside child components.

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

  1. Step 1: Understand the role of props

    Props are designed to send data from a parent component down to its child components.
  2. 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.
  3. Final Answer:

    To pass data from a parent component to a child component -> Option A
  4. 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

  1. Step 1: Identify Vue 3 <script setup> syntax

    In Vue 3 with <script setup>, props are declared using defineProps().
  2. Step 2: Match the correct syntax for prop declaration

    const props = defineProps({ title: String }) correctly declares a prop named title of type String.
  3. Final Answer:

    const props = defineProps({ title: String }) -> Option A
  4. Quick Check:

    Vue 3 <script setup> uses defineProps() [OK]
Hint: Use defineProps() inside
Common Mistakes:
  • Using options API syntax inside
  • Declaring props as local refs
  • Forgetting to use defineProps() in
3. Given the parent component template:
<ChildComponent :message="'Hello Vue'" />

And the child component script setup:
const props = defineProps({ message: String })
console.log(props.message)

What will be logged to the console?
medium
A. undefined
B. 'Hello Vue'
C. An error because props.message is read-only
D. null

Solution

  1. Step 1: Understand prop passing

    The parent passes the string 'Hello Vue' as the message prop to the child.
  2. Step 2: Accessing the prop in child

    The child uses defineProps to declare message and logs props.message, which holds 'Hello Vue'.
  3. Final Answer:

    'Hello Vue' -> Option B
  4. Quick Check:

    Passed prop value logs correctly [OK]
Hint: Props hold passed values, accessible via props object [OK]
Common Mistakes:
  • Expecting props to be undefined without declaration
  • Confusing read-only with inaccessible
  • Assuming props are null if not reactive
4. What is wrong with this child component code that tries to modify a prop?
<script setup>
const props = defineProps({ count: Number })
props.count = props.count + 1
</script>
medium
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

  1. Step 1: Recall prop immutability

    Props in Vue are read-only inside child components and cannot be directly modified.
  2. 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.
  3. Final Answer:

    Props are read-only and cannot be assigned new values -> Option D
  4. 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>
C.
<script setup>
const props = defineProps({ users: Array })
</script>
<template>
  <ul>
    <li v-for="user in props.users" :key="user">{{ user }}</li>
  </ul>
</template>
D.
<script setup>
const props = defineProps({ users: String })
</script>
<template>
  <ul>
    <li v-for="user in props.users" :key="user">{{ user }}</li>
  </ul>
</template>

Solution

  1. Step 1: Check prop declaration type

    The parent passes an array, so the child must declare users as type Array using defineProps({ users: Array }).
  2. Step 2: Verify template usage

    The child uses v-for to loop over props.users and display each user in a list item, which is correct.
  3. Final Answer:

    The code using defineProps({ users: Array }) and v-for on props.users -> Option C
  4. Quick Check:

    Array prop with defineProps and v-for works [OK]
Hint: Match prop type to passed data and loop in template [OK]
Common Mistakes:
  • Declaring wrong prop type (e.g., String instead of Array)
  • Not using defineProps in
  • Trying to mutate props inside child
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard