Parent and child components call variables and methods each other

One, the parent component obtains the variables and methods of the child component

1. Define a ref when calling subcomponents

<rchild ref="myChild"></rchild>

2. Pass in the parent component

this.$refs.myChild.属性
this.$refs.myChild.方法()

Second, the child component gets the variables and methods of the parent component

Write directly in the subcomponent:

this.$parent.属性
this.$parent.方法()

——————— 但是 ————————

The way the child component obtains the parent component's variables is not powerful enough and can be used daily. Knowing props is what you have to do (required for enterprises)
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_45629623/article/details/107543892