What answer would you give to a rhetorical question like the title? Most people would say yes even if they didn’t know, because it’s not just anecdotal evidence.

To this question, the answer is indeed: yes!

So how do you do that?

Methods a

Using the $emit

// Parent component code:
<child @created="doSomething" />

// Subcomponent code:
created() {
    this.$emit('created')}Copy the code

This will trigger the parent’s doSomething method when the child calls the Created hook.

However, this function is implemented, but it does not seem elegant enough! Is there a more elegant way?

Rhetorical questions again… I just wanted to know if you were scared?

Well, the answer is: yes!

Method 2:

Using the @ hook:

// Parent component code
<child @hook:created="doSomething"/>
Copy the code

What? And that’s it?

Yeah, that’s it! There are no child components…

Hook: What is it? Why haven’t you seen it?

Indeed, there is no hook description on the official website! At this point, we can only sacrifice the [original code] to:

Source code parsing:

The eventsMixin method checks whether the event name monitored by V-ON starts with hook: and if so, sets the ‘_hasHookEvent’ value for the corresponding lifetime to true. If ‘_hasHookEvent’ is true, then ‘$emit(‘hook:’ + corresponding lifecycle hook)’ will be emitted

So, the principle of method two is the same as method one, but the framework has taken care of it for us! Elegant and convenient