短信验证,冷却时间

短信验证,倒计时60秒

由于是使用vue进行编写,vant的框架,里面会有vant的组件,但是核心代码是js

//html
// 我这里是做了样式判断 如果是不可点击则用前一种css否则用后者
<div :class="canClick==true?'getVerificationCode':'getVerificationCode-on'" @click="getVerificationCode">
	<div>{{content}}</div>
</div>
// data
content:'提交', // 按钮初始的文字
time:60,  //倒计时时间
canClick: true, // 可点击获取验证码条件
toSubmit: 0 , // 是否提交过
// js
getVerificationCode(){
	 //判断是否可点击
	 if (!this.canClick) return
	 // 做了一个vant的加载动画,可不要
	 Toast.loading({
	   message: '加载中...',
	   forbidClick: true,
	   duration: 0, 
	   loadingType: 'spinner'
	 });
	 //你的接口
	 .then(res => {
	   if(res.errcode === 1) {
	   	 // 接口成功(发出消息)
	     Toast.clear();
	     Toast.success(res.errmsg)
	     console.log('成功')
	     this.canClick = false
	     this.content = this.time + 's后可发送'
	     // 时间自减
	     let clock = window.setInterval(() => {
	       this.time--
	       this.content1 = this.time + 'sTente'
	       // 时间小于0的时候恢复
	       if (this.time < 0) {
	         window.clearInterval(clock)
	         this.content = '提交'
	         this.time = 60
	         this.canClick = true
	       }
	     },1000)
	   }
	 })
	 .catch(err => {
	   console.log(err)
	 })
},
.getVerificationCode{
  text-align: center;
  background-color: rgb(5,155,251);
  color: white;
  width: 100px;
  height: 28px;
  font-size: 12px;
  line-height: 13px;;
  display: -webkit-box;
  word-break: break-all;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  text-overflow: ellipsis;
  border-radius: 10px;
}
.getVerificationCode-on{
  text-align: center;
  background-color: #cccccc;
  color: white;
  width: 100px;
  height: 28px;
  font-size: 12px;
  line-height: 13px;;
  display: -webkit-box;
  word-break: break-all;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  text-overflow: ellipsis;
  border-radius: 10px;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值