button
<el-button type="info" size="small" plain :disabled="countdown>0?true:false"
@click="sendYzm()">{{ countdown > 0 ? `${countdown} 秒后重新获取` : '获取验证码' }}</el-button>
javascript
export default {
data() {
return {
countdown:0,
}
},
methods: {
startTimer() {
const interval = setInterval(() => {
if (this.countdown > 0) {
this.countdown--
} else {
clearInterval(interval)
}
}, 1000)
},
sendYzm() {
if (this.form.email == "") {
this.$message({
message: "邮箱不能为空!",
type: 'warning'
});
} else {
this.$http.post("login/userRegist/sendYzm/?email=" + this.form.email).then(resp => {
if (resp.data.code == 200) {
this.$message({
message: resp.data.message,
type: 'success'
});
this.countdown=60;
this.startTimer();
}
})
}
}
},
mounted() {
}
}