html

    1. <div class="phoneyzm_lis2" @click="CodeBln ? clickNumberCodeFnc() : ''"></div>

    js

    1. data(){
    2. return{
    3. CodeBln: false,
    4. // 倒计时秒数
    5. timeIntinvel: null,
    6. // 按钮上的文字
    7. codeMsg: "获取验证码",
    8. }
    9. },
    10. methods:{
    11. clickNumberCodeFnc(){
    12. //防止多次点击(上面html已经有了可以选择不要)
    13. if (this.CodeBln == true) {
    14. return;
    15. }
    16. clearInterval(that.timeIntinvel);//清理定时器
    17. that.CodeBln = false;//把按钮变成不可点击
    18. let index = 60;//读秒
    19. //开始倒计时
    20. that.timeIntinvel = setInterval(() => {
    21. index--;
    22. if (index <= 0) {
    23. index = 0;
    24. that.CodeBln = true;
    25. that.codeMsg = "获取验证码";
    26. } else {
    27. that.codeMsg = `<span style="color:#ff190e">${index}S</span>重新获取`;
    28. }
    29. }, 1000);
    30. }
    31. }