Vue gets the data of the child component in the parent component

I just started using this.$emit event, but the child component cannot trigger the event, so the data of the child component cannot be obtained using this method.

I found out by accident today that I can directly use the following method to obtain it, simple and easy to use

This is my subcomponent:

Parent component:

 

use:

 

 effect:

to sum up:

That is, define a ref when calling the child component, and then use this.$refs.child. attribute

extend:

Then, if the child component wants to get the data and methods in the parent component, you can use it in the child component:

​ this.$parent.data

​ this.$parent.method

Guess you like

Origin blog.csdn.net/qq_41588568/article/details/106498778