博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
获取验证码
阅读量:4100 次
发布时间:2019-05-25

本文共 1326 字,大约阅读时间需要 4 分钟。

获取验证码之前,先检测有没有手机号

之前做的时候用的vue, 里面存在的变量大都是取义的,相信各位童鞋都会懂的大笑

getCode: function () {

            let self = this;

//          if(!this.getCode) return ;  
//          this.getCode = false;
            //验证手机号
            let telReg = /^1(3|4|5|6|7|8|9)\d{9}$/;
            let phone = self.form.phone;
            if('' == phone) { tip('请输入手机号码'); return ;}       //tip为一个提示消息函数(做的时候在移动端)
            if(!telReg.test(phone)) { tip('请输入正确手机号'); return ;}    //正则验证
            let time = self.form.countdown;

            if(self.form.countdown != 60){ tip('验证码已发送,请稍等...'); return ;}

 

 //发送验证码

            axios({

            method:"POST",
                url: this.path+'sms/'+phone,
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                },
                transformRequest: [function(data) {
                    let ret = '';
                    for (let it in data) {
                        ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&';
                    }
                    return ret
                }]
            }).then(data => {
//          this.getCode = true;
                if(data.data.code == 100000){

                    tip('验证码已发送...');

 

###############################################

//敲黑板!!!(这个里面就是倒计时的效果啦) 成功回调,倒计时,为一个自执行函数

            (function settime(){

            if(time == 0 || self.form.code != ''){

                self.form.codeText = '获取验证码';
                self.form.countdown = 60;
                return ;
            }else {
                self.form.codeText = time + ' 秒';
                self.form.countdown = time;
                time-- ;
                setTimeout(function(){
                    settime();
                },1000);
            }

        })()

######################################

 

  //其余为失败回调

                }else if(data.data.code == 100006){

                tip(data.data.result);
                }}).catch(err => console.log(err));

        },

~~~

 

你可能感兴趣的文章
Guava快速入门
查看>>
Java编程基础:static的用法
查看>>
Java编程基础:抽象类和接口
查看>>
Java编程基础:异常处理
查看>>
Spring MVC中使用Thymeleaf模板引擎
查看>>
Spring处理表单提交
查看>>
Spring MVC异常处理
查看>>
Leetcode 1180. Count Substrings with Only One Distinct Letter [Python]
查看>>
PHP 7 的五大新特性
查看>>
php实现socket(转)
查看>>
PHP底层的运行机制与原理
查看>>
深入了解php底层机制
查看>>
PHP中的stdClass 【转】
查看>>
XHProf-php轻量级的性能分析工具
查看>>
PHP7新特性 What will be in PHP 7/PHPNG
查看>>
比较strtr, str_replace和preg_replace三个函数的效率
查看>>
ubuntu 下编译PHP5.5.7问题:configure: error: freetype.h not found.
查看>>
PHP编译configure时常见错误 debian centos
查看>>
configure: error: Please reinstall the BZip2 distribution
查看>>
OpenCV gpu模块样例注释:video_reader.cpp
查看>>