Vue.js concept of component-under

Source: Internet
Author: User

One, the communication between components

The scope of the component instance is orphaned, which means that the data of the parent component cannot and should not be referenced directly within the child component's template. However, there is a need for communication between parent and child components, which the child component needs to communicate to the parent component to pass data to the child component.

in Vue.js, the parent-child component's relationship can be summarized as props down, events up. The parent component passes data down through props to the child component, which sends a message to the parent component through events. As shown in the following:

  

Second, prop-parent component pass data to child component

prop is a custom property that the parent component uses to pass data. Subcomponents need to explicitly declare "prop" with the props option:

Vue.component (' child ', {

//Declaration props

props: [' message '],

//Just like data, prop can be used within the template

//can also be used in VM instances like "This.message"

Template: ' <span>{{message}}</span> '

})

2.1 Simple pass-through values

Vue.js concept of component-under

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.