Vue Props

Vue Tutorial

Vue Props

In Vue.js, props (properties) are used to pass data from a parent component to a child component.

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:

Parent → Child (via props)
  •  Read-only
  •  Reactive
  •  Reusable

 Basic Props Example

 Parent Component


 Child Component


 

  •  The child receives name from 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

  • true automatically

 Props vs Data (Important)

FeaturePropsData
OwnerParentComponent
MutabilityRead-onlyMutable
PurposeConfigurationState

 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

TaskUse
Pass dataProps
Update parentEmits
Local stateData
Validate inputProp validation

Conclusion

Vue props are the foundation of component communication and reusability.
Mastering props helps you build clean, scalable, and maintainable Vue apps.

You may also like...