在vue中beforeDestroy()中移除requestAnimationFrame方法启动的动画

问题:在页面上添加了动画,切换页面后会报错,如下图:

 报错是因为离开有动画的页面后,没有取消动画

// requestAnimationFrame方法启动的动画
this.timeIndex = requestAnimationFrame((time) => draw(time, canvas, ctx));

// 销毁前取消动画
beforeDestroy() {
    cancelAnimationFrame(this.timeIndex); 
},

猜你喜欢

转载自www.cnblogs.com/stella1024/p/13175599.html