最近项目中需要实现获取验证码的功能,这里做了一个简单实现方式。

废话不多说,直接撸代码。。。。。

<div class="purse-mid-yanzheng">
                    <span class="purse-mid-yanzheng-one">验证码</span>
                    <input type="text" placeholder="请输入验证码" />
                    <span  class="purse-mid-yanzheng-two" @click="sendVcode(mobile)" id="yzm">获取验证码</span>
</div>

js:

export default {
        data: function() {
            return {
                times: "60", //60秒倒计时
            }
        },
        methods: {
            //发送验证码,校验手机号
            sendVcode: function(moblie) {
                alert(moblie);
                var that = this;
                var regMoblie = /^1[345678]\d{9}$/;
                if(!regMoblie.test(moblie)) {
                    msg('该手机号格式错误');
                    return;
                }            
            $.ajax({
                    type: "post",
                    url: "/send_verification_code.do",
                    async: true,
                    data: {
                        mobile: moblie
                    },
                    dataType: "json",
                    success: function(result) {
                        if(result.result_code == 0) {
                            msg("获取验证码成功,请注意短信查收!");
                            that.countdown();
                        } else {
                            msg("获取验证码失败!");
                            console.log("获取验证码失败");
                        }
                    },
                    error: function() {
                        msg("服务器发生异常,请稍后再试!");
                    }
                });
            },
            //60秒倒计时
            countdown: function() {
                var that = this;
                if(that.times == 0) {
                    $('#yzm').html("获取验证码");
                    that.times = 60;
                    return false;
                } else {
                    $('#yzm').html("" + that.times + "s");
                    that.times--;
                }
                setTimeout(function() {  
                    that.countdown();
                }, 1000);
            },
        },
        mounted: function() {
          
        }
    };

ps:  setInterval 实现倒计时,并清除计时器 //周期执行

需求:60s倒计时,自动执行agree();函数,也可以点击执行,返回时要清除计时器

export default {
    data: function() {
        return {
            time: 60,
            interval: ""
        }
    },
    methods: {
        goback: function() {
            clearInterval(this.interval);  //清除计时器
            window.history.go(-1);
        },
        countdown: function() {
            let that = this;
            let interval = window.setInterval(function() {
                that.interval = interval;
                if ((that.time--) <= 1) {
                    clearInterval(interval);
                    that.agree(); //执行函数
                }
            }, 1000);
        }
    },
    mounted: function() {
        this.countdown();   //网页加载完成时调用
    }
};,

vue.js—60秒倒计时相关推荐

  1. 简单实现vue验证码60秒倒计时功能

    简单实现vue验证码60秒倒计时功能 <span v-if="codeShow" @click="getPhoneCode">点击获取验证码< ...

  2. vue 微信录音倒计时_Vue实现发送短息60秒倒计时

    原文:https://blog.csdn.net/weixin_43201015/article/details/84405352 Vue实现注册账号时,发送短信60秒倒计时功能,并进行手机号校验的D ...

  3. Vue实现发送短息60秒倒计时

    Vue实现发送短息60秒倒计时 Vue实现注册账号时,发送短信60秒倒计时功能,并进行手机号校验的Demo案例,如果能帮到您,我感到非常荣幸,废话不多说,直接上干货, 首先来一个测试页面,引入Vue. ...

  4. vue+elementui 实现点击验证码出现60秒倒计时

    vue+elementui 实现点击验证码出现60秒倒计时 div部分 <div class="verCode@click="getVerCode":disable ...

  5. vue获取手机验证码60秒倒计时,不能点击按钮

    vue获取手机验证码60秒倒计时,不能点击按钮 export const resend = element => {console.log(element)var num = 60var tim ...

  6. vue中实现60秒倒计时

    vue中实现60秒倒计时 <span>{{count}} s</span> data中: data(){return{show: true,count: '',timer: n ...

  7. vue页面实现短信验证码60秒倒计时

    废话不多说,直接上代码. template <div class='single-wrapper fs14'><div class='single-mb'>短信验证</d ...

  8. 免费获取验证码60秒倒计时

    免费获取验证码60秒倒计时 <!DOCTYPE html> <html> <head> <script src="http://libs.baidu ...

  9. 榛子云短信-微信小程序60秒倒计时插件

    为了帮助开发者更便捷的使用微信小程序的短信验证码功能,特别是初学者更好的使用,榛子云短信特地开发了60秒倒计时插件,效果: 使用方法 1.引入插件countdown.js var CountDown ...

  10. 微信小程序60秒倒计时

    大家可以直接使用插件: https://blog.csdn.net/zuoliangzhu/article/details/90140067 微信小程序发送短信验证码后60秒倒计时功能,效果图: 完整 ...

最新文章

  1. oracle 授权 增删改查权限_linux suid,sgid,sticky-bit三种特殊权限简介
  2. linux创建redis容器,docker-compose实现redis部署及键值添加
  3. Exchange服务器系列课程之七--维护邮件服务器(二)
  4. 9550电机_电机转矩与性能的关系
  5. 让我来教你 PHP 函数调用
  6. 【飞谷六期】爬虫项目1
  7. 如何在Centos 7上用Logrotate管理日志文件
  8. Dubbo生产者消费者配置
  9. Android Touch事件传递机制 二:单纯的(伪生命周期)
  10. 简述推荐系统中的矩阵分解
  11. 使用haskell来解线性方程
  12. SQL Server CTE 递归查询全解
  13. ios-deploy out of date (1.9.4 is required). To upgrade with Brew: brew upgrade ios-deploy
  14. 矩池云conda创建指定cuda cudnn tf版本的虚拟环境
  15. 软件测试52讲-测试新技术篇
  16. 使用百度富文本编辑器UEditor碰到的问题
  17. java毕设项目开源啦,springboot+vue+springcloud的家庭理财系统
  18. Swing 主题 - FlatLaf
  19. WPF界面样式学习及优化
  20. Mysql 查询患某种疾病的患者

热门文章

  1. Mockplus 3.2前瞻,五大特色功能让你惊喜!
  2. 15b万用表怎么测电容_手工改造丨把15B万用表隐藏的功能利用起来~
  3. Python ADF检验
  4. 正斜杠,又称左斜杠,符号是/;反斜杠,也称右斜杠,符号是\。
  5. go实现文档中保存的微信图片.dat格式解密为图片
  6. c语言考试可视化编辑器无法提交,一行代码解决The7升级后可视化编辑器不能正常工作的问题...
  7. python 爬阳光高考高校数据
  8. 队列同步器(AbstractQueuedSynchronizer)源码简析
  9. js获取某年某月某天是第几周
  10. 组态王通过Modbus TCP与ESP32通讯