Provide access to lifecycle hooks of a child component (e.g. if 3rd party component)
What problem does this feature solve?
When data is changed in the parent but the template is actually rendered in a child, the updated hook
of the parent will not trigger.
That means if the child component is a closed/external component (3rd party) there is no way to know when the DOM has been updated.
This is problematic when we rely on the render result to execute logic (generate custom print previews e.g.), as nextTick can be quite unpredictable and Vue's internal batching will prevent checking render results in a chain of updates.
The general advice now seems to watch for data changes, but as changed Data != DOM Update this does not help.
In vue2 I believe there was an @hook:EVENT
that could be listened to from the parent.
https://vuedose.tips/listen-to-lifecycle-hooks-on-third-party-vue-js-components
What does the proposed API look like?
<ChildComponent @hook:updated="doOnUpdated()" />
Would be great if we could register and access the child's hooks in the setup function of the parent (through a ref?), after the child has been mounted.
You can already do this. These hooks was renamed to onVnodeXXX
<Comp @vnodeUpdated="doSomething" />
h(Comp, {
onVnodeUpdated: doSomething,
onVnodeMounted: doSomething,
// etc..
})