验证码自动输入
2、点击获取验证码
3、代码⽰例
<view >
<view>
<input
v-model="userPwdPhone"
type="text"
maxlength="20"
placeholder="请输⼊动态验证码"
placeholder-/>
</view>
<view @tap="getPhonecode">{{deText}}</view>
</view>
var codeBtn={
codeTime:60,
codeText:"获取验证码",
codeStatus:true
};
//⼿机号码验证规则
var rules ={
userName:{
rule:/\S/,
msg:"账号不能为空"
},
userNamePhone:{
rule:/^1[3456789]\d{9}$/,
msg:"⼿机号格式错误"
},
userPwdPhone:{
rule:/^[0-9]{6}$/,
msg:"请输⼊6位数字验证码"
}
};
// 获取验证码时,验证⼿机号是否正确,并且验证是否在60s后重新发送
getPhonecode(){
console.log(this.validate('userNamePhone')&&deStatus);
if(this.validate('userNamePhone')&&deStatus){
}
}
// 验证
validate(key){
let bool=true;
if(!this.rules[key].st(this[key])){
uni.showToast({
title:this.rules[key].msg,
icon:'none'
})
bool=false;
return false;
}
return bool;
}
/
/请求服务获取短信验证码
getValidataCode(){
let t =this;
'/mobile/user/getValidateCode', "GET",
{
userNamePhone:t.userNamePhone },
function(res){
if(res.status =='0001'){
let timerId =setInterval(()=>{
let codetime = deTime; codetime--;
if(codetime <1){
clearInterval(timerId)
}
},1000)
}else if(res.status =='0003'){
uni.showToast({
title:'验证码不正确!',
icon:'none'
})
}
}
);
}
效果图如下: