Skip to content

Provide access to lifecycle hooks of a child component (e.g. if 3rd party component)  #4345

@TuringJest

Description

@TuringJest

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions