I have a simple component hierarchy, in which there is one parent component, which contains the following template <div><component :is="current"></component></div>
and two child components, which are dynamically 'switched' out, via the value of current
.
The logic for the 'switching' of components is being handled in the parent component. However, when I try to execute a method in the second child component (in response to an event emitted from the first child component, being listened to in the parent component, and altering the value of current
in the parent component) through the mounted
lifecycle hook, the expected result is not observed.
Essentially, I cannot find a decent way of invoking a child component's methods when that component is 'switched' in as the current component in the parent component.
I have realistically looked at using the $refs
and $children
properties on the instance, but these do not seem to be of any assistance. I have also reasoned using the event system. I usually 'define' an event listener in the mounted
lifecycle hook, however, I refer to the 'issue' of using the lifecycle hooks
What is the usual approach to this situation?