Article From:https://segmentfault.com/q/1010000012141777

The problem I put forward is a “middleman” mode that transmits data, that is, the subcomponent A sends data, the parent component receives the data, and then passes the data to the sub component B by binding.

app.compentThe (buy) = “buyHandler ($event)” binding operation in the main component needs to be triggered by the button click event in the child component. What is the relationship between the $event parameters of the main components and the sub components?

If the parameter $event is removed from the sub components, the normal operation of the program will not be affected, and the $event parameter in the main component is necessary.

The subcomponents are as follows:

The main components are as follows:

Answer 0:

Event of father and son component is not necessary.

The event parameter of the parent component is a parameter passed by the receiving sub component. If your sub component does not launch a (EMIT) parameter, then the event of the parent component is not necessary. This is also common, that is, the parent component only needs to know that the child component has triggered a certain behavior, but it does not need to.The sub component handles the corresponding business logic, which is handled by the parent component. The seed component is called the so-called fool component, which is simple to do page rendering, does not handle too much logic, but has high reuse, which is a function of the puppet component in the React.

The event parameter of the sub component is event, which represents the event you click on, which is the event of the ordinary DOM event. There is nothing to say.

Note that is $event, not event, in fact what the name of the parameter can, why add a $, we generally default $the beginning of the variable is the meaning of the flow, and emit is the flow of the NodeJS, so you know, do not be misled by this event, the parent componentThis event non subcomponent of the other event.

Answer 1:

Parent components that need to be triggered by child component binding events.$eventIt is a subcomponentemitOutgoing value subcomponent$eventIt’s the click of the event
It is specific to refer to the corresponding@Output()File

Leave a Reply

Your email address will not be published. Required fields are marked *