Vue · Junior · Question 36 of 75
How do you give a prop a default value and make another one required?
defineProps({
title: { type: String, required: true },
size: { type: String, default: "md" },
});- ✓Correct answer: With the object syntax:
required: trueanddefault - 2With
?and=inside the template - 3Defaults can only be set in the parent
Explanation
Vue warns in development when a required prop is missing or has the wrong type. For object or array defaults use a factory function: default: () => [].