VDone Demo VDone Demo
Home
  • Articles

    • JavaScript
  • Study Notes

    • JavaScript Tutorial
    • Professional JavaScript
    • ES6 Tutorial
    • Vue
    • React
    • TypeScript: Build Axios from Scratch
    • Git
    • TypeScript
    • JS Design Patterns
  • HTML
  • CSS
  • Technical Docs
  • GitHub Tips
  • Node.js
  • Blog Setup
  • Learning
  • Interviews
  • Miscellaneous
  • Practical Tips
  • Friends
About
Bookmarks
  • Categories
  • Tags
  • Archives
GitHub (opens new window)

Nikolay Tuzov

Backend Developer
Home
  • Articles

    • JavaScript
  • Study Notes

    • JavaScript Tutorial
    • Professional JavaScript
    • ES6 Tutorial
    • Vue
    • React
    • TypeScript: Build Axios from Scratch
    • Git
    • TypeScript
    • JS Design Patterns
  • HTML
  • CSS
  • Technical Docs
  • GitHub Tips
  • Node.js
  • Blog Setup
  • Learning
  • Interviews
  • Miscellaneous
  • Practical Tips
  • Friends
About
Bookmarks
  • Categories
  • Tags
  • Archives
GitHub (opens new window)
  • 基础

  • 组件

    • Component Usage Details
    • Passing Data from Parent to Child Components
      • One-Way Data Flow
      • Parent-Child Data Passing Demo
    • Child Component Emitting Events and Values to Parent
    • Prop Validation and Non-Prop Attributes
    • Custom Events
    • Sibling Component Communication
    • Non-Parent-Child Component Communication
    • Parent Calling Child Component Methods with Arguments
    • Slots
    • Dynamic Components and v-once Directive
    • Vue Parent-Child Component Lifecycle Order
  • 过渡&动画

  • 可复用性&组合

  • 工具

  • 规模化

  • Vuex

  • 其他

  • 《Vue》笔记
  • 组件
xugaoyi
2020-02-04
Contents

Passing Data from Parent to Child Components

# Passing Data from Parent to Child Components

In the parent component, pass values to the child component by binding attributes with v-bind on the child component tag:

<ComponentName v-bind:name="value"></ComponentName>
1

Without v-bind, the passed value is a string literal. With v-bind binding, the passed value is an expression. In the child component, receive the values through the props object:

 props: {
    name: { // receive the value passed from the parent
        type: String || ...,
        default: ''
    }
 }
1
2
3
4
5
6

# One-Way Data Flow

All props form a one-way-down binding between the child and parent: when the parent prop updates, it will flow down to the child, but not the other way around. This prevents child components from accidentally mutating the parent's state, which would make the data flow of your application difficult to understand.

Child components cannot directly modify values passed from the parent

There are two common cases where you might be tempted to mutate a prop:

  1. The prop is used to pass an initial value; the child component wants to use it as a local data property. In this case, it's best to define a local data property that uses the prop as its initial value:
props: ['initialCounter'],
data: function () {
  return {
    counter: this.initialCounter
  }
}
1
2
3
4
5
6
  1. The prop is passed in as a raw value that needs to be transformed. In this case, it's best to define a computed property using the prop's value:
props: ['size'],
computed: {
  normalizedSize: function () {
    return this.size.trim().toLowerCase()
  }
}
1
2
3
4
5
6

# Parent-Child Data Passing Demo

See the Pen mdJVqgg by xugaoyi (@xugaoyi) on CodePen.

Edit (opens new window)
#Vue
Last Updated: 2026/03/21, 12:14:36
Component Usage Details
Child Component Emitting Events and Values to Parent

← Component Usage Details Child Component Emitting Events and Values to Parent→

Recent Updates
01
How I Discovered Disposable Email — A True Story
06-12
02
Animations in Grid Layout
09-15
03
Renaming a Git Branch
08-11
More Articles >
Theme by VDone | Copyright © 2026-2026 Nikolay Tuzov | MIT License | Telegram
  • Auto
  • Light Mode
  • Dark Mode
  • Reading Mode