You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 does the proposed API look like?
A documentation enhancement.
The text was updated successfully, but these errors were encountered:
It' true. Well i have finded that on code (core/instance/events.js):
consthookRE=/^hook:/Vue.prototype.$on=function(event: string|Array<string>,fn: Function): Component{constvm: Component=thisif(Array.isArray(event)){for(leti=0,l=event.length;i<l;i++){vm.$on(event[i],fn)}}else{(vm._events[event]||(vm._events[event]=[])).push(fn)// optimize hook:event cost by using a boolean flag marked at registration// instead of a hash lookupif(hookRE.test(event)){vm._hasHookEvent=true}}returnvm}Vue.prototype.$once=function(event: string,fn: Function): Component{constvm: Component=thisfunctionon(){vm.$off(event,on)fn.apply(vm,arguments)}on.fn=fnvm.$on(event,on)returnvm}
Then i can use hook: with $on or $once. I can put a simple string or use a array with Array.isArray(event) like:
I'm not sure if this hasn't been documented because it's not considered public API. In any case, it should be in Vuejs/vuejs.org repo. I couldn't find any open issue there
What problem does this feature solve?
I've just recently learned from the 3rd sources that
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 does the proposed API look like?
A documentation enhancement.
The text was updated successfully, but these errors were encountered: