vue发送验证码状态变化

html:

<group class="login_input">
<span class="number_label">验证码</span>
<x-input class="weui-vcode" @on-change="codeNumber" :show-clear="false">
<x-button slot="right" type="primary" mini class="sendNumber" :disabled="this.registration_data.disable001" :style="{ background: this.registration_data.sendCodeStyle.background }" @click.native="sendCode">{{this.registration_data.sendCodeText}}</x-button>
</x-input>
</group>

js:

data () {
return {
registration_data:{
code:"",
sendCodeStyle: {background: ''},
sendCodeText: '发送验证码',
sendCodeTime: 0,
sendCodeTimeLength: 60,
disable001:false
}
}
},
codeNumber(value){
this.registration_data.code=value;
},
sendCodeCountDown(){//倒计时后发送验证码状态的改变
if(this.registration_data.sendCodeTimeLength > 0){
this.registration_data.sendCodeText = ' '+this.registration_data.sendCodeTimeLength+'秒 ';
this.registration_data.disable001 = true;//点击后button禁用
this.registration_data.sendCodeStyle.background = 'grey';
this.registration_data.sendCodeTimeLength--;
setTimeout(this.sendCodeCountDown,1000);
}else{
this.registration_data.disable001 = false;
this.registration_data.sendCodeText = '发送验证码';
this.registration_data.sendCodeStyle.background = '';
this.registration_data.sendCodeTimeLength = 60;
return;
}
},

 sendCode(){//发送验证码
let that=this;
if(!this.registration_data.phone){
this.showAlert("提示","请填写手机号");
}
let time = Date.parse(new Date());// 1970/01/01 到现在时间的毫秒数
if(time >(this.registration_data.sendCodeTime+this.registration_data.sendCodeTimeLength*1000)){
this.registration_data.sendCodeTime = time;
}
let data = {
//发送的数据
};
that.$http.post(url, that.params(data),{
emulateJSON: true,
headers: {
'Content-Type' : 'application/x-www-form-urlencoded'
}
}).then(
function (res){
if(res.data.respcode=="00"){
that.sendCodeCountDown();
}
else{
that.showAlert("提示",res.data.msg);
}
},
function (error){

}

)
},
 
 



转载于:https://www.cnblogs.com/HONGYE1994/p/8078899.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值