ionic3中短信验证码从后台获取倒计时间

在做手机app的时候难免会遇到短信验证码问题,身为做Android原生的我,接触ionic 也有半年多,但界面设计对我来说真的很头疼,这不搞了个验证码废了很大的劲,分享出来与大家共享。其实代码没多少比较简单

1.html中
<ion-item >
      <ion-label>
        验  证  码
      </ion-label>
      <ion-input placeholder="请输入验证码" [(ngModel)]="item.phoneCode"></ion-input>
      <button color="custom" item-right ion-button (click)="getCode()" [disabled]="!verifyCode.disable">{{verifyCode.verifyCodeTips}}</button>
    </ion-item>
2.ts中
    //验证码倒计时
    verifyCode: any = {
        verifyCodeTips: "获取验证码",
        countdown: 120,//总共时间
        disable: true
    }
 //倒计时
    settime() {
        if (this.verifyCode.countdown == 0) {
            debugger
            this.verifyCode.verifyCodeTips = "获取验证码";
            this.verifyCode.disable = true;
            return;
        } else {
            this.verifyCode.countdown--;
        }
        setTimeout(() => {
            this.verifyCode.verifyCodeTips = "重新获取" + this.verifyCode.countdown + "秒";
                this.settime();
        }, 1000);
    }
再从后台获取到时间的时候调用settime()即可。


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值