Subscribe on changes!
avatar
Feb 6th 2021

What problem does this feature solve?

The hook events allow a parent component to perform actions after a child component has passed a lifecycle stage (e.g. mounted) and solves asynchronous mounting of parent and child components which is not always reliably solvable by accessing "nextTick". This is especially useful for third-party-components when it is not possible to create a custom event during the mounted-lifecycle of the child component.

I believe this feature had been implemented in Vue 2 already, but was never documented and thus probably dropped. See example and vue2 codebase for where I believe the previous implementation for the feature (partially) resides

What does the proposed API look like?

<template>
      ...
     <child-component @hook:mounted="doWhatever" />
      ...
</template>
avatar
Feb 6th 2021

It is already implemented (not documented though). Use it like this @vnodeHookName="fn"

<child-component @vnodeMounted="doWhatever" />

in js

h(ChildComponent, {
  onVnodeMounted() {
    // ...
  }
})
avatar
Feb 6th 2021

Ah gotcha, thanks for pointing it out!

avatar
Feb 6th 2021

发自我的iPhone

在 2021年2月7日,上午3:40,plc-dev notifications@github.com 写道:

 Ah gotcha, thanks for pointing it out!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.