vue下循环定时器只运行了一次的问题

https://img4.mukewang.com/5c35a99100017c1012430241.jpg

    let timer_this = this;

    function changeSendBtn () {

        if (sendTime<0){

            console.log('清除定时器');

            timer_this.sendBtnTitle = '发送验证码';

            clearInterval(timer_this.sendBtnTimer);

            return false;

        }

        timer_this.sendBtnTitle = sendTime+'s';

        sendTime--;

        console.log(sendTime)

    }

    this.sendBtnTimer = setInterval(changeSendBtn(),1000);

写了一个定时器,但是只运行一次,高手们帮我看下原因所在

眼眸繁星
浏览 2921回答 1
1回答

忽然笑

你单独运行下面这段代码看看const test = () => {let sendTime = 2let sendBtnTimer = setInterval(changeSendBtn,1000)function changeSendBtn() {&nbsp; &nbsp; if (sendTime<0){&nbsp; &nbsp; &nbsp; &nbsp; console.log('清除定时器');&nbsp; &nbsp; &nbsp; &nbsp; clearInterval(sendBtnTimer);&nbsp; &nbsp; &nbsp; &nbsp; return false;&nbsp; &nbsp; }&nbsp; &nbsp; sendTime--;&nbsp; &nbsp; console.log(sendTime)}}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript