My Vue application has a countdown feature that is not functioning correctly and I am not sure why.
When I view {{ $parent.timer }}
, I can see the correct value.
Here is the data section of my Vue application:
data: function() {
return {
timer : 3,
...
Below is the countdown function I am using:
countdown : function(time,callback)
{
//time is equal 5
this.timer = time;
//this.timer is equal 5
var timerInterval = undefined;
timerInterval = setInterval(function() {
if(this.timer == 1) {
this.timer = 0;
callback();
return clearInterval(timerInterval);
}
// First time undefined, in 2nd is NaN
this.timer -= 1;
// NaN
}, 1000);
}
To call the function:
this.countdown(data.time,function(){ //smtng });
Can someone please help me figure out what I am doing wrong? This countdown function used to work in my previous Vue application.
Thank you in advance for any assistance!