Problem Statement
How do you validate props and provide defaults? Why is it important?
Explanation
Use a props object with type, required, default, and validator. Validation catches incorrect usage early; defaults make components resilient and self-documenting. For object/array defaults, return a factory function to avoid shared references.
Code Solution
SolutionRead Only
props: {
options: {
type: Array,
default: () => []
},
mode: {
type: String,
validator: v => ['light','dark'].includes(v)
}
}