vue.js—60秒倒计时
最近项目中需要实现获取验证码的功能,这里做了一个简单实现方式。
废话不多说,直接撸代码。。。。。
<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秒倒计时相关推荐
- 简单实现vue验证码60秒倒计时功能
简单实现vue验证码60秒倒计时功能 <span v-if="codeShow" @click="getPhoneCode">点击获取验证码< ...
- vue 微信录音倒计时_Vue实现发送短息60秒倒计时
原文:https://blog.csdn.net/weixin_43201015/article/details/84405352 Vue实现注册账号时,发送短信60秒倒计时功能,并进行手机号校验的D ...
- Vue实现发送短息60秒倒计时
Vue实现发送短息60秒倒计时 Vue实现注册账号时,发送短信60秒倒计时功能,并进行手机号校验的Demo案例,如果能帮到您,我感到非常荣幸,废话不多说,直接上干货, 首先来一个测试页面,引入Vue. ...
- vue+elementui 实现点击验证码出现60秒倒计时
vue+elementui 实现点击验证码出现60秒倒计时 div部分 <div class="verCode@click="getVerCode":disable ...
- vue获取手机验证码60秒倒计时,不能点击按钮
vue获取手机验证码60秒倒计时,不能点击按钮 export const resend = element => {console.log(element)var num = 60var tim ...
- vue中实现60秒倒计时
vue中实现60秒倒计时 <span>{{count}} s</span> data中: data(){return{show: true,count: '',timer: n ...
- vue页面实现短信验证码60秒倒计时
废话不多说,直接上代码. template <div class='single-wrapper fs14'><div class='single-mb'>短信验证</d ...
- 免费获取验证码60秒倒计时
免费获取验证码60秒倒计时 <!DOCTYPE html> <html> <head> <script src="http://libs.baidu ...
- 榛子云短信-微信小程序60秒倒计时插件
为了帮助开发者更便捷的使用微信小程序的短信验证码功能,特别是初学者更好的使用,榛子云短信特地开发了60秒倒计时插件,效果: 使用方法 1.引入插件countdown.js var CountDown ...
- 微信小程序60秒倒计时
大家可以直接使用插件: https://blog.csdn.net/zuoliangzhu/article/details/90140067 微信小程序发送短信验证码后60秒倒计时功能,效果图: 完整 ...
最新文章
- oracle 授权 增删改查权限_linux suid,sgid,sticky-bit三种特殊权限简介
- linux创建redis容器,docker-compose实现redis部署及键值添加
- Exchange服务器系列课程之七--维护邮件服务器(二)
- 9550电机_电机转矩与性能的关系
- 让我来教你 PHP 函数调用
- 【飞谷六期】爬虫项目1
- 如何在Centos 7上用Logrotate管理日志文件
- Dubbo生产者消费者配置
- Android Touch事件传递机制 二:单纯的(伪生命周期)
- 简述推荐系统中的矩阵分解
- 使用haskell来解线性方程
- SQL Server CTE 递归查询全解
- ios-deploy out of date (1.9.4 is required). To upgrade with Brew: brew upgrade ios-deploy
- 矩池云conda创建指定cuda cudnn tf版本的虚拟环境
- 软件测试52讲-测试新技术篇
- 使用百度富文本编辑器UEditor碰到的问题
- java毕设项目开源啦,springboot+vue+springcloud的家庭理财系统
- Swing 主题 - FlatLaf
- WPF界面样式学习及优化
- Mysql 查询患某种疾病的患者
热门文章
- Mockplus 3.2前瞻,五大特色功能让你惊喜!
- 15b万用表怎么测电容_手工改造丨把15B万用表隐藏的功能利用起来~
- Python ADF检验
- 正斜杠,又称左斜杠,符号是/;反斜杠,也称右斜杠,符号是\。
- go实现文档中保存的微信图片.dat格式解密为图片
- c语言考试可视化编辑器无法提交,一行代码解决The7升级后可视化编辑器不能正常工作的问题...
- python 爬阳光高考高校数据
- 队列同步器(AbstractQueuedSynchronizer)源码简析
- js获取某年某月某天是第几周
- 组态王通过Modbus TCP与ESP32通讯