Присвойте свой интервал переменной и затем сбросьте его:
this.interval = setInterval(() => {
// do something here
}, 1000);
И сброс:
if (this.interval) clearInterval(this.interval);
this.interval = null;
Что касается вашего кода , вы создаете пустую переменную/ интервал, а затем очистить его, который выдает ошибку.
И объявить переменную для интервала глобально.
let interval3;
И запустить его внутри функции:
function runInterval() {
this.timeLeftForPlantThree = 120;
const a = 1000;
if (!this.interval3) {
this.interval3 = setInterval(() => {
if (this.timeLeftForPlantThree > 0) {
this.timeLeftForPlantThree--;
this.plantThreeRed = false;
console.log(this.timeLeftForPlantThree);
} else {
console.log('***' + this.timeLeftForPlantThree);
this.plantThreeRed = true;
}
}, a);
}
}
Исбросить его:
function resetInterval() {
if (this.interval) clearInterval(this.interval);
this.interval = null;
}