DEV Community

Discussion on: How to Stop requestAnimationFrame in Vuejs / Javascript

Collapse
coolgoose profile image
Alexandru Bucur Author

I don't understand what you mean unfortunately.

Destroy is the vue method for when the component isn't active on the page. And we are just doing cleanup, it's not a few milliseconds after.

Collapse
timkor profile image
Timkor • Edited on

No exactly. You are now cancelling an on create requested animation frame on destroy. But the animation frame will pretty much all the times already being fired.

I was just wondering if you could provide a scenario where a Vue component is created and deleted within a few milliseconds.

Thread Thread
elliott_regan profile image
Elliott Regan • Edited on

The benefit could be when this.fancyFunctionHere kicks off a recursive loop, like an animation.

fancyFunctionHere() {
    this.id = requestAnimationFrame(this.fancyFunctionHere);
}