Vue验证码60秒倒计时功能简单实例代码

前端之家收集整理的这篇文章主要介绍了Vue验证码60秒倒计时功能简单实例代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

template

script

export default { data() { return { // 是否禁用按钮 codeDisabled: false,// 倒计时秒数 countdown: 60,// 按钮上的文字 codeMsg: '获取验证码',// 定时器 timer: null } },methods: { // 获取验证码 getCode() { // 验证码60秒倒计时 if (!this.timer) { this.timer = setInterval(() => { if (this.countdown > 0 && this.countdown <= 60) { this.countdown--; if (this.countdown !== 0) { this.codeMsg = "重新发送(" + this.countdown + ")"; } else { clearInterval(this.timer); this.codeMsg = "获取验证码"; this.countdown = 60; this.timer = null; this.codeDisabled = false; } } },1000) } } } }

css(scss写法)

.login{ width: 100%; height: 100%; background: #F9F9F9; .loginHeader{ padding: 0 10px; background: #fff; margin-top: 20px; overflow: hidden; .loginBtn{ width: 100%; height: 42px; border: none; background: #fff; color: #444; border-radius: 4px; outline: none; padding-left: 3px; font-size: 1.4rem; Box-sizing: border-Box; -webkit-appearance:none; } .border-bottom{ border-bottom: 1px solid #F3F3F3; } .codeBtn{ width: 63%; height: 42px; border: none; background: #fff; color: #444; border-radius: 4px; float: left; outline: none; padding-left: 3px; font-size: 1.4rem; Box-sizing: border-Box; -webkit-appearance:none; } .getNumber{ width: 35%; height: 36px; float: right; margin-top: 3px; border: 1px solid #09BB07; color: #09BB07; background: #fff; border-radius: 4px; outline: none; -webkit-appearance:none; } } }

总结

以上所述是小编给大家介绍的Vue验证码60秒倒计时功能简单实例代码。编程之家 jb51.cc 收集整理的教程希望能对你有所帮助,如果觉得编程之家不错,可分享给好友!感谢支持

原文链接:https://www.f2er.com/vue/31818.html

猜你在找的Vue相关文章