Routed components call methods of other components.

my Vue project is like this. My body is a routed page that can jump to many pages (eg: a, b, c component). header and footer both exist on the page when routing to different pages.

there are some methods in my header , but when I body routes to the b component, I want to call the method of a component in the b component. What should I do?

Mar.12,2021

according to your description, b component and a component are sibling relationships in routing, not parent-child relationships, and cannot exist on the page at the same time. We can't call each other at this time.

it is recommended that you extract the methods that need to be called and maintain them in a separate module, so that you do not have to call in the component.


1. It can be understood that you want to implement the communication between components, then you can use vuex or eventbus to implement, emit an event in the b component, and handle
2 in the header component. If only some internal methods are common, you can put them in mixin

Menu