Is there a way to restart the Interval after it has been cleared? I am trying to make a button clickable once every 11 seconds. I have disabled the button while the timer is greater than 0, and once it reaches 0, the button becomes clickable again. The current code I have seems to work, but if I call the setInterval() function multiple times, the timer starts counting down too quickly. Are there any solutions for this issue?
data:{
sTimer:11,
sDisabled:true,
asd:null
},
methods:{
testing(){
this.sTimer--;
if(this.sTimer == 0){
clearInterval(this.asd);
this.sTimer= 11;
this.sDisabled = false;
}else{
this.sDisabled = true;
}
},
specialAttack(){
setInterval(() => this.testing(), 1000)
}
},
created(){
this.asd = setInterval(() => this.testing(), 1000);
}
<button class="specialAttack" :disabled="sDisabled" @click="specialAttack(); testing()">Special Attack {{ sTimer }}</button>