uni-app获取短信验证码

uni-app获取短信验证码uni-app获取短信验证码
验证码自动输入
1、输⼊⼿机号
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'
})
}
}
);
}
效果图如下:

本文发布于:2024-09-21 03:12:03,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/2/386332.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:验证码   获取   验证   短信   机号   账号   不能   是否
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议