html部分代码
<van-button slot="button" size="small" type="primary" class="codeBtn" :disabled="!regShow" @click="getCode">
<span v-show="regShow">获取验证码</span>
<span v-show="!regShow">{{count}} s后重新获取</span>
</van-button>
export default{
data(){
return{
user:{dl_name:'',dl_password:'',dl_password2:'',verificationCode:''},
regShow: true,
count: '',
timer: null,
}
},
methods:{
check:function(that){
let that=this;
if (that.user.dl_name === "") {
Toast('姓名不能为空');
return false;
}else if(that.user.dl_name.length>20){
Toast('姓名超长');
}else if (that.user.dl_phone=== "") {
Toast('电话不能为空');
return false;
}else if (that.user.dl_password === "") {
Toast('密码不能为空');
return false;
}else if (that.user.dl_password2 === "") {
Toast('确认密码不能为空');
return false;
}else if(that.user.dl_password.length>6&&that.user.dl_password.length<20){
Toast('密码长度不在6-20内');
return false
} else if (that.user.dl_password != that.user.dl_password2) {
Toast('两次输入密码不同');
return false;
}else if (that.user.verificationCode === "") {
Toast('验证码不能为空');
return false;
}
return true;
},
getCode(){
let that=this;
let regexp1 = /^[0-9]*$/g;
let reg=/^[1][3,4,5,7,8][0-9]{9}$/;
if(that.user.dl_phone===""){
Toast('电话不能为空');
return false;
}
if(!regexp1.test(that.user.dl_phone)){
Toast('电话填有额外字符');
return false;
}
if(that.user.dl_phone.length!=11){
Toast('电话位数错误');
return false;
}
if(!reg.test(that.user.dl_phone)){
Toast("电话格式不正确");
return false;
}
console.log(this.user)
this.$http.get(...)
.then(function(response){
that.infoList=response.data.data
if (response.data.code > 399) {
Toast(response.data.msg);
}
})
.catch(function(err){
Toast(err.msg);
});
const TIME_COUNT = 60;
if (!this.timer) {
this.count = TIME_COUNT;
this.regShow = false;
this.timer = setInterval(() => {
if (this.count > 0 && this.count <= TIME_COUNT) {
this.count--;
} else {
this.regShow = true;
clearInterval(this.timer);
this.timer = null;
}
}, 1000)
}
}
}
}