If i follow your example to the letter, all works fine.
However, if i choose to do this:
x-init="init()" - i do this because i just like to have the bulk of my functionality inside x-data.
And inside x-data i have the init function what happens is this:
init runs twice(because i see the message in the console twice.
It decrements the seconds 2 by 2(which makes sense, if init is called twice).
Why does that happen?
Hello again! I ran into a weird situation.
If i follow your example to the letter, all works fine. However, if i choose to do this:
x-init="init()" - i do this because i just like to have the bulk of my functionality inside x-data.
And inside x-data i have the init function what happens is this: init runs twice(because i see the message in the console twice. It decrements the seconds 2 by 2(which makes sense, if init is called twice). Why does that happen?
x-data="{ secondsLeft: 10, init(){ console.log('it runs'); window.setInterval(() => { if(this.secondsLeft > 0) this.secondsLeft = this.secondsLeft - 1; }, 1000); } }"