Overview
Props are custom attributes you can register on a component. They enable parent components to pass data down to child components.Basic Usage
With <script setup>
Array Syntax
Object Syntax
runtime-core/src/apiSetupHelpers.ts:48-59
Without <script setup>
Type-Based Props Declaration
With TypeScript, you can declare props using pure types:runtime-core/src/apiSetupHelpers.ts:83-87
With Default Values
UsewithDefaults() to provide defaults for type-based props:
runtime-core/src/apiSetupHelpers.ts:364-378
Prop Types
Basic Type Constructors
Multiple Types
runtime-core/src/componentProps.ts:70
Prop Validation
PropOptions Interface
runtime-core/src/componentProps.ts:55-68
Validation Examples
Type Inference
ExtractPropTypes
Extract prop types from runtime declarations:runtime-core/src/componentProps.ts:143-150
DefineProps Type
runtime-core/src/apiSetupHelpers.ts:96-98
Prop Casing
Vue automatically converts between camelCase and kebab-case:Boolean Props
Boolean props have special casting behavior:Props Destructuring
Destructuring props in<script setup> maintains reactivity:
Rest Properties
The compiler creates a proxy for rest properties:runtime-core/src/apiSetupHelpers.ts:473-487
Runtime Validation
Prop validation runs in development mode:Advanced Patterns
Complex Type Validation
Optional Props with Union Types
Generic Props
Prop Mutability
Props are readonly and should not be mutated:- Use computed properties for transformations:
- Emit events to request parent updates:
- Use local state for local modifications:
Prop Type Definitions
PropType
runtime-core/src/componentProps.ts:70-81
Component Props Options
runtime-core/src/componentProps.ts:43-49
Best Practices
- Always specify prop types for better validation and documentation
- Use type-based declarations with TypeScript for compile-time safety
- Provide defaults for optional props to avoid undefined checks
- Mark required props explicitly with
required: true - Use validators for complex validation logic
- Never mutate props - use events or local state instead
- Use factory functions for object/array defaults
- Leverage destructuring in
<script setup>for cleaner code
Related APIs
- Events - Learn about emitting events from child components
- v-model - Learn about two-way binding with props
- defineModel - Learn about the model helper