How to Stop requestAnimationFrame in Vuejs / Javascript

20 Jul 19 12:28
One minute read


let id = window.requestAnimationFrame(fancyFunctionHere)

Now for the longer version. Technically in Vue.js you might have components/mixins that use window.requestAnimationFrame. Since the fancyFunctionHere is used as a callback, everytime you call window.requestAnimationFrame you are going to get a new id that you should use on the destroy method to stop it.

Unfortunately this is not imediately clear on MDN so hopefully my documentation edit with the comment in the code example goes trough.

    created() { = window.requestAnimationFrame(

    destroyed() {
        window.cancelAnimationFrame(; = undefined;

    data() {
        return {
            id: undefined

    methods: {
        fancyFunctionHere() {


« Back to posts