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" },
});

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: () => [].

Further reading

Problem with a question

Vue · Junior · question 36

Test yourself

Take the Vue · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz