定时器使用function时,this指向window对像,使用箭头函数时,this指向vue对象
若要指向vue对象,则使用箭头函数
例子
setInterval(()=>{
this......// 这个this指向vue对象
},1000)
setInterval(function(){
this....// 这个this指向window对象
},1000)
定时器使用function时,this指向window对像,使用箭头函数时,this指向vue对象
若要指向vue对象,则使用箭头函数
例子
setInterval(()=>{
this......// 这个this指向vue对象
},1000)
setInterval(function(){
this....// 这个this指向window对象
},1000)