vuejs
/

Vue Props

Last Sync: Today

On this page

10
0%
5 min read
Remaining
5 minleft

Click any section to jump — progress syncs automatically

vuejs

Vue Props

What are Props?

Props are custom attributes used to pass data from a parent component to a child component in Vue.

Basic Example

HTMLRead-only
1
<child-component message="Hello"></child-component>
JavaScriptRead-only
1
export default {
  props: ['message']
}

Dynamic Props

HTMLRead-only
1
<child-component :count="num"></child-component>

Props Validation

JavaScriptRead-only
1
props: {
  title: String,
  age: Number
}

Default Values

JavaScriptRead-only
1
props: {
  name: {
    type: String,
    default: 'Guest'
  }
}

Required Props

JavaScriptRead-only
1
props: {
  id: {
    type: Number,
    required: true
  }
}

One-Way Data Flow

Props follow a one-way data flow, meaning data flows from parent to child only.

Best Practices

  • Validate props types
  • Use default values when needed
  • Keep props immutable
  • Use descriptive prop names

Common Mistakes

  • Modifying props directly
  • Not validating props
  • Using unclear prop names
  • Passing unnecessary data

Conclusion

Props are essential for communication between components in Vue. Proper usage ensures clean and maintainable code.

Try it yourself

export default { props: ['message'] }

Test Your Knowledge

Q1
of 3

Props used for?

A
Loop
B
Event
C
Passing data
D
Condition
Q2
of 3

Data flow?

A
Two-way
B
One-way
C
Three-way
D
No flow
Q3
of 3

Props should be?

A
Mutable
B
Immutable
C
Global
D
Static

Frequently Asked Questions

What are props?

They pass data from parent to child components.

Are props mutable?

No, props should not be modified directly.

What is prop validation?

It ensures correct data types for props.

Previous

vue components intro

Next

vue events

Related Content

Need help?

Explore our comprehensive docs or start a chat with our tech experts.