Vue Props

Vue Props
They are the main way components communicate downward.
What are Props?
Props are custom attributes that you register on a component so it can receive data from its parent.
Data flow:
- Read-only
- Reactive
- Reusable
Basic Props Example
Parent Component
Child Component
- The child receives
namefrom the parent.
Dynamic Props (v-bind)
Use v-bind (:) to pass dynamic values.
Multiple Props
Props with Types (Recommended)
- Helps catch bugs
- Better readability
Props with Validation
Passing Objects & Arrays
- Props are reactive — changes in parent update child.
Props are Read-Only
Wrong:
Correct:
Emit event to parent
Use local copy
Props Naming Rules
JavaScript
Template
- camelCase → kebab-case
Boolean Props
trueautomatically
Props vs Data (Important)
| Feature | Props | Data |
|---|---|---|
| Owner | Parent | Component |
| Mutability | Read-only | Mutable |
| Purpose | Configuration | State |
Common Mistakes
- Mutating props directly
- Not validating props
- Using props instead of state
- Passing too many props
Best Practices
- Validate props
- Keep props simple
- Use emits for updates
- Prefer objects for grouped data
- Document props clearly
Summary Table
| Task | Use |
|---|---|
| Pass data | Props |
| Update parent | Emits |
| Local state | Data |
| Validate input | Prop validation |
Conclusion
Vue props are the foundation of component communication and reusability.
Mastering props helps you build clean, scalable, and maintainable Vue apps.
