首页 > 其他分享 >Angular 使用window.requestAnimationFrame循环调用导致,异常ERROR TypeError: Cannot read properties of undefined

Angular 使用window.requestAnimationFrame循环调用导致,异常ERROR TypeError: Cannot read properties of undefined

时间:2023-03-20 16:45:59浏览次数:50  
标签:TypeError undefined read requestAnimationFrame 箭头 window 调用 animate 方法

异常:

 

 

 调用方法

当使用requestAnimationFrame调用animate()时出现异常

原因requestAnimationFrame调用时this是就不指当前对象了,this指向的就是requestAnimationFrame的内部

解决方法:

将animate()换成箭头方法

使用箭头方法,确保该方法没有自己的this,并将当前对象用作this

 

 或者在requestAnimationFrame处使用匿名箭头函数调用animate()进行循环

 

标签:TypeError,undefined,read,requestAnimationFrame,箭头,window,调用,animate,方法
From: https://www.cnblogs.com/sugarwxx/p/17236830.html

相关文章