Method: 1. Call the method of the parent component through "this.$parent.event" in the child component. 2. The child component uses "$emit" to trigger an event to the parent component, and the parent component can listen to this event. 3. The parent component passes the method to the child component, and the method can be called directly in the child component.
The operating environment of this tutorial: Windows 7 system, vue version 2.9.6, DELL G3 computer.
In Vue, the sub-component calls the parent component. Here are three methods for reference.
The first methodis directly in the sub-component. Call the method of the parent component through this.$parent.event
Parent component
Child component
The second methodis in the child Use$emit
in the component to trigger an event to the parent component, and the parent component can listen to this event.
Parent component
Subcomponent
The third typeis that the parent component passes the method into the subcomponent, in the subcomponent Call this method directly
parent component
child component
[Related recommendations:vue.js tutorial]
The above is the detailed content of How does a vue subcomponent call the method of the parent component?. For more information, please follow other related articles on the PHP Chinese website!