Mutual communication between grandparents and grandchildren

1. Use $attrs to realize data transfer between grandparents and grandchildren components

First, there are three components: father (grandpa), childDom (dad), and childrenDom (grandson)

Pass in two data foo and coo in the father (grandfather) component

 Then add v-bind="$attrs" to the childDom (dad) component, which is quite a bridge for connecting grandpa to grandson data

 Finally receive it in the childrensonDom (grandchildren) component.

 The effect is as shown in the figure

2. Use $listeners to realize data transfer between Sun Chuanye components

First pass a data "upRocket" with $emit in the childrensonDom (grandson) component

 Then add a bridge to the childDom (dad) component, and this bridge is v-on="$listeners"

 Finally, it is received in the father (grandpa) component

 Then you can realize that the grandson component launches the rocket and receives the rocket in the grandpa component, the effect is as shown in the figure

 

Guess you like

Origin blog.csdn.net/Mr_xiaoxuboke/article/details/125490094