Vue Props – Pass Data Between Components in Vue.js (2025 Guide)
Introduction – What Are Props in Vue?
In Vue.js, props (short for properties) are the primary way to pass data from a parent component to a child component. They form the backbone of Vue’s component communication system and are critical for creating reusable, modular components.
In this guide, you’ll learn:
- What props are and why they’re important
- How to define, pass, and validate props
- The difference between static and dynamic props
- Best practices and common mistakes
What Is a Prop in Vue?
A prop is a custom attribute on a child component tag that lets you pass data from the parent to the child.
Basic Example:
<!-- Parent Component -->
<ChildComponent message="Hello from Parent" />
// ChildComponent.vue
props: ['message']
message will be available as a reactive variable inside the child.
Defining Props in Components
Using an Array (Simple Syntax)
props: ['title', 'count']
Using an Object (Detailed with Validation)
props: {
title: String,
count: {
type: Number,
required: true,
default: 0
}
}
This allows type checking, defaults, and required flags.
Passing Static vs Dynamic Props
Static (Hardcoded):
<Alert message="Static Text" />
Dynamic (Uses JavaScript variable):
<Alert :message="alertText" />
The : tells Vue to evaluate the expression instead of using a string literal.
Full Working Example – Prop Communication
Parent Component:
<ProductCard :product="item" />
data() {
return {
item: { name: 'Laptop', price: 999 }
}
}
Child Component (ProductCard.vue):
<template>
<div>
<h2>{{ product.name }}</h2>
<p>${{ product.price }}</p>
</div>
</template>
<script>
export default {
props: ['product']
}
</script>
The child now displays information passed from the parent via product.
Common Prop Issues
Using props as data (mutation):
// Avoid mutating props directly
this.message = 'Changed';
Use a local copy if needed:
data() {
return {
localMessage: this.message
};
}
Prop Type Validation and Defaults
| Property | Purpose |
|---|---|
type | Validates the prop type |
default | Sets a fallback value if not provided |
required | Throws warning if missing |
Example:
props: {
price: {
type: Number,
default: 0,
required: true
}
}
One-Way Data Flow
Props are one-way bound: data flows from parent ➝ child, not the other way.
This makes component communication predictable and easy to debug.
Real-World Example – Button with Label
Reusable Button:
<template>
<button>{{ label }}</button>
</template>
<script>
export default {
props: {
label: {
type: String,
required: true
}
}
}
</script>
Parent:
<BaseButton label="Submit" />
<BaseButton label="Cancel" />
Easy-to-reuse component with different labels via props.
Syncing Props with Events (v-model + modelValue)
In Vue 3, you can use v-model with props like modelValue:
Child:
<template>
<input :value="modelValue" @input="$emit('update:modelValue', $event.target.value)" />
</template>
<script>
export default {
props: ['modelValue']
}
</script>
Parent:
<TextInput v-model="name" />
Seamless two-way binding using props + emit.
Summary – Recap & Next Steps
Props in Vue are essential for passing data from parent to child components. They enable component reusability, logic separation, and maintainable architecture in Vue apps.
Key Takeaways:
- Props pass data downward from parent to child
- Use
props: []or an object with validation - Props are read-only and one-way
- Use
modelValueand$emitfor two-way communication
Real-World Relevance:
Props power dynamic interfaces like product cards, form inputs, alerts, dropdowns, and reusable UI components.
FAQ Section
What is a prop in Vue?
A prop is a way to pass data from a parent component to a child component via custom attributes.
How do I validate props?
Use the object syntax:
props: {
title: { type: String, required: true }
}
Are props reactive?
Yes, props are reactive. If the parent updates the value, the child receives the new data automatically.
Can a child component modify a prop?
No. Props are read-only. Use a local copy in data() if you need to modify it.
How to implement two-way binding with props?
Use v-model with modelValue and emit update:modelValue from the child.
Share Now :
