Skip to content

Please explain that "hook:<>" events exist and they allow to subscribe to the Vue component lifecycle events #2247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
WillAvudim opened this issue Jul 25, 2019 · 3 comments

Comments

@WillAvudim
Copy link

What problem does this request solve?

I've just recently learned from the 3rd sources that

vue_component.$once('hook:beforeDestroy', function () { ... } )
can be used to subscribe to the lifecycle events of individual components.

In my case this is very convenient, it enables me to automatically shut down the no longer necessary websocket connection that is used to receive real-time updates on a certain page of my SPA.

Would it be possible to mention this great fact in the official documentation? I couldn't find any reference to it anywhere. There are several mentioning of the word hook in the documentation and they all seem to connote some other unrelated things.

What will the proposed change look like?

A documentation enhancement.

What is the use case and what needs to be covered?

A sample write up is provided at vuejs/vue#10312.

@phanan
Copy link
Member

phanan commented Jul 25, 2019

As @posva commented in the linked issue, this feature is internal and shouldn't be relied on – especially with Vue 3 approaching.

@phanan phanan closed this as completed Jul 25, 2019
@sirlancelot
Copy link
Contributor

It's worth pointing out that the hook: syntax is documented appropriately under Handling Edge Cases: Programmatic Event Handlers.

@lobo-tuerto
Copy link

An example is documented, but there is no list of all the existing hook:X events.
Even though it'll be safe to assume every lifecycle hook will fire a hook:X event, it's not noted anywhere I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants