JS---setInterval()优雅实现短信倒计时功能

it2025-05-04  10

好久没接触过JS简单记录下今天完成的小demo,代码比较精简只贴了倒计时功能

getPhoneCode() { let second = 60 let test = setInterval(() => { if (second > 0){ --second this.timer = `(${second}) 秒后重新发送` }else { clearInterval(test) this.second = 60 this.timer = '获取短信验证码' } }, 1000) }
最新回复(0)