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
After refactoring my project to replace $dispatch/$broadcast with an empty global Vue instance as a message bus using $on/$emit, I'm finding that if I call vm.$on() from the created() hook of a component, the component's entire state shows up in vm as vm._events.eventName[n].function scope.Closure._this.
Which is all well and good until a component gets destroyed, at which point the events it registered with vm.$on() seem to live forever and keep firing with the complete state it had just before it was destroyed.
Even if I were to add a 'deleted' flag to my components and use it to prevent them from doing anything, they're still setting in memory forever.
Is this a bug, or am I skipping a step somewhere in the component destruction process?
groovy9, web3w, mh0625, youliangxiong, lijiaxi and 14 more01xunsicheng, rex-ll, mvc1006 and zhengyongbo01xunsicheng, zhengyongbo and fuyz01xunsicheng and zhengyongbozhengyongbo
Activity
yyx990803 commentedon Aug 6, 2016
If the event is registered on an external bus, you need to tear it down in
beforeDestroy
ordestroyed
.If this gets repetitive, you can write a mixin to automate this.
groovy9 commentedon Aug 6, 2016
What's the process for tearing it down? I haven't been able to find that in the docs.
yyx990803 commentedon Aug 6, 2016
vm.$off
geekskai commentedon Apr 25, 2020
You can refer to this:
eventBus.js