mounted(){
setInterval(()=>{
this.amount--
},1000);
if (this.amount == 0)
clearInterval();
},
(props로 amount 데이터 전송 함)
mounted 됐을 때 amount 값 1초당 1씩 내리면서 0에 도달했을 때 clearInterval() 한 건데 먹히질 않네..
ClearInterval() 말고 this.amount == 0 등 0으로 할당하거나 동작을 멈추려고 해도 도저히 안 돼........
clearInterval(intervalID)
setInterval 할때 리턴값이 있을텐데 const discount_id = setInterval() 하고 clearInterval(discount_id)
https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/clearInterval
뷰 문제가 아니라 js 문제다.
그럼 setInterval()을 변수로 지정하는게 맞는 거임?
id알아야 기억했다 지움
https://stackoverflow.com/questions/9747139/javascript-setinterval-clearing-itself
mounted(){ var STOP = setInterval(()=>{ this.amount-- },1000); if (this.amount == 0){ clearInterval(STOP) } }, 이것도 효과가 없다!
if를 amount-- 다음에 넣어야지 ㅋㅋ
안된다 씨 1 발
혹시몰라서 말하는데 STOP하고 amount 콘솔에 찍어보는건 기본이다
setInterval 안에 있는 콜백함수에서 clear해야지 mounted 함수는 마운트 되었을때 발생하는 이벤트인데 뷰 라이프사이클에 대해 잘못 이해한듯
스택오버플로우 답글보면 setInterval(()=>{//이 안에서 if문 넣고 clear하잖아})