How does the parent component use the values in the child component when the vue child component does not trigger an event?

problem description

the child component does not have any click event to trigger, so the data needs to be loaded out. How can the parent component receive the values in the child component?

the environmental background of the problems and what methods you have tried

uses $children, no event triggers, and always gets a value of undefiend.

is there any good way to solve this problem?

Apr.05,2021

you can use ref to get the instance of the subcomponent, through which you can get all the values, and even call the methods of the subcomponent.


you can notify the child component with event this.$emit ('test', somedata) when the parent component invokes the child component < Child @ test= "test" / >
and then in the methods of your parent component,

test(somedata){
    //somedatasomedata
}

official usage of $emit

Menu