Components, Props & Emits Questions with Answers

25 practice questions on Components, Props & Emits (Vue.js) with answers and step-by-step solutions. Try 10 samples below, then practise all 25 free in the AptiNest app.

Sample questions

Question 1Easy

What is the correct way to pass a number 5 as prop max?

  1. :max="5"
  2. max="5"
  3. max=5 as a string always
  4. @max="5"

Answer: A. :max="5"

Explanation

Without v-bind the value is a string; :max passes the JavaScript expression 5.

Step-by-step solution

  1. Prefix with colon.
  2. The expression evaluates to a number.

Why the other options are wrong

  • B. Without colon it is the string '5'.
  • C. It would pass the string.
  • D. @ is for events.

Question 2Easy

What are slots used for?

  1. Declaring reactive state that the child owns privately
  2. Registering client-side routes for the component tree
  3. Creating a global store shared across all components
  4. Letting a parent supply content for the child's template

Answer: D. Letting a parent supply content for the child's template

Explanation

Slots provide content distribution; the child decides where the parent's content appears.

Step-by-step solution

  1. Slots let a parent pass template content into a child component.
  2. The child decides where that content appears in its own template.
  3. So slots let a parent supply content for the child's template (option D).

Why the other options are wrong

  • A. Private state is declared with ref or reactive, not with slots.
  • B. Client routes are set up with the router, not with slots.
  • C. A global store is a separate pattern, not a slot.

Tip: Use slots for reusable layouts where the parent decides the content.

Question 3Easy

How does a parent pass data to a child component?

  1. Through emits
  2. Through slots only
  3. Through v-once
  4. Through props

Answer: D. Through props

Explanation

Props flow down from parent to child.

Step-by-step solution

  1. The child declares props, and the parent passes values to them as attributes.
  2. Data flows down from parent to child through props.
  3. So the parent passes data through props (option D).

Why the other options are wrong

  • A. Emits send events up to the parent, not data down.
  • B. Slots pass template content, not data props.
  • C. v-once renders once; it does not pass data.

Tip: Props go down, events go up.

Question 4Easy

Which macro declares the props in <script setup>?

  1. defineProp
  2. defineProps
  3. setProps
  4. useProps

Answer: B. defineProps

Explanation

defineProps is a compiler macro available without import.

Step-by-step solution

  1. Call defineProps in script setup.
  2. Receive props as an object.

Why the other options are wrong

  • A. Singular name does not exist.
  • C. setProps is not a Vue API for this; the correct choice is defineProps.
  • D. useProps is not a Vue API for this; the correct choice is defineProps.

Question 5Medium

What happens by default to attributes (like class) a parent passes that the child does not declare as props, for a single-root component?

  1. Extra attributes and listeners land on the root element
  2. They are silently discarded unless declared as props
  3. They throw a warning and stop rendering the component
  4. They are merged into the component's props object

Answer: A. Extra attributes and listeners land on the root element

Explanation

Fallthrough attributes such as class and @click are added to the root element automatically.

Step-by-step solution

  1. Attributes such as class or click listeners that the child does not declare as props are fallthrough attributes.
  2. For a component with a single root element, Vue adds them to that root element.
  3. Nothing is discarded and no warning is raised.
  4. So the answer is option A: they land on the root element.

Why the other options are wrong

  • B. Undeclared attributes are not discarded; they fall through to the root.
  • C. No warning is thrown and rendering continues.
  • D. They are not merged into the props object.

Tip: Use inheritAttrs false with a v-bind on another element when the root should not receive fallthrough attributes.

Question 6Medium

Which prop declaration makes size required and numeric at runtime?

  1. defineProps({ size: { type: Number, required: true } })
  2. defineProps({ size: Number!})
  3. defineProps({ size: Number! }) which marks the numeric type as mandatory
  4. defineProps({ size: 'Number' })

Answer: A. defineProps({ size: { type: Number, required: true } })

Explanation

Object syntax with type and required provides runtime validation.

Step-by-step solution

  1. Use the object form.
  2. Add type and required.

Why the other options are wrong

  • B. Number! is a syntax error in a props object; use { type: Number, required: true }.
  • C. A trailing! does not mark a prop as mandatory; the required: true option does.
  • D. Type must be a constructor, not a string.

Question 7Medium

How should a default for an object prop be set?

  1. default: {}, written directly as an object literal shared by all instances
  2. default: new Object
  3. default: null always
  4. Use a factory function: default: () => ({})

Answer: D. Use a factory function: default: () => ({})

Explanation

Factory defaults create a fresh object per component instance.

Step-by-step solution

  1. Object defaults must be functions.
  2. Each instance gets its own copy.

Why the other options are wrong

  • A. A shared object literal is not allowed for objects.
  • B. new Object shares a single instance.
  • C. null is not an empty object.

Question 8Medium

Which macro declares the events a component can emit in <script setup>?

  1. defineEmits()
  2. defineProps()
  3. defineEvents()
  4. defineSlots() only

Answer: A. defineEmits()

Explanation

defineEmits(['change']) returns the emit function.

Step-by-step solution

  1. DefineEmits declares the events that a component can emit.
  2. It returns the emit function that sends them.
  3. So defineEmits is the macro (option A).

Why the other options are wrong

  • B. DefineProps declares inputs, not events.
  • C. DefineEvents is not a Vue macro.
  • D. DefineSlots declares slots, not events.

Tip: Declare events with defineEmits, then send them with the returned emit function.

Question 9Hard

What does the child emit('update:title', v) allow?

  1. The child to change the parent's data directly
  2. The parent can bind it with v-model:title
  3. Server communication
  4. Naming a CSS class

Answer: B. The parent can bind it with v-model:title

Explanation

v-model:title expands to :title plus @update:title.

Step-by-step solution

  1. Parent binds v-model:title.
  2. Child emits update:title.
  3. Parent assigns the value.

Why the other options are wrong

  • A. Only an event is sent; the parent updates itself.
  • C. Emit is local to components.
  • D. It is an event name.

Question 10Hard

What does inheritAttrs: false allow?

  1. Blocking all props from reaching the child so that only attributes are accepted
  2. Applying fallthrough attributes to an inner element using $attrs
  3. Removing the root element
  4. Disabling events

Answer: B. Applying fallthrough attributes to an inner element using $attrs

Explanation

By default non-prop attributes land on the root element. Turning it off lets you spread v-bind="$attrs" where you want.

Step-by-step solution

  1. Set inheritAttrs false.
  2. Bind $attrs to inner element.

Why the other options are wrong

  • A. Props are separate from attrs.
  • C. The root remains.
  • D. Listeners are part of attrs.

Practise all 25 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all Vue.js topics · All topics