Sample questions
Question 1Easy
What is the correct way to pass a number 5 as prop max?
- :max="5"
- max="5"
- max=5 as a string always
- @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
- Prefix with colon.
- 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
- Declaring reactive state that the child owns privately
- Registering client-side routes for the component tree
- Creating a global store shared across all components
- 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
- Slots let a parent pass template content into a child component.
- The child decides where that content appears in its own template.
- 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?
- Through emits
- Through slots only
- Through v-once
- Through props
Answer: D. Through props
Explanation
Props flow down from parent to child.
Step-by-step solution
- The child declares props, and the parent passes values to them as attributes.
- Data flows down from parent to child through props.
- 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>?
- defineProp
- defineProps
- setProps
- useProps
Answer: B. defineProps
Explanation
defineProps is a compiler macro available without import.
Step-by-step solution
- Call defineProps in script setup.
- 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?
- Extra attributes and listeners land on the root element
- They are silently discarded unless declared as props
- They throw a warning and stop rendering the component
- 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
- Attributes such as class or click listeners that the child does not declare as props are fallthrough attributes.
- For a component with a single root element, Vue adds them to that root element.
- Nothing is discarded and no warning is raised.
- 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?
- defineProps({ size: { type: Number, required: true } })
- defineProps({ size: Number!})
- defineProps({ size: Number! }) which marks the numeric type as mandatory
- 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
- Use the object form.
- 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?
- default: {}, written directly as an object literal shared by all instances
- default: new Object
- default: null always
- 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
- Object defaults must be functions.
- 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>?
- defineEmits()
- defineProps()
- defineEvents()
- defineSlots() only
Answer: A. defineEmits()
Explanation
defineEmits(['change']) returns the emit function.
Step-by-step solution
- DefineEmits declares the events that a component can emit.
- It returns the emit function that sends them.
- 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?
- The child to change the parent's data directly
- The parent can bind it with
v-model:title - Server communication
- 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
- Parent binds v-model:title.
- Child emits update:title.
- 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?
- Blocking all props from reaching the child so that only attributes are accepted
- Applying fallthrough attributes to an inner element using
$attrs - Removing the root element
- 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
- Set inheritAttrs false.
- 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 →