SendVerifyCode.js 569B

123456789101112131415161718192021222324252627
  1. export default {
  2. data() {
  3. return {
  4. disabled: false,
  5. text: "获取验证码"
  6. };
  7. },
  8. methods: {
  9. sendCode() {
  10. if (this.disabled) return;
  11. this.disabled = true;
  12. let n = 60;
  13. this.text = "剩余 " + n + "s";
  14. const run = setInterval(() => {
  15. n = n - 1;
  16. if (n < 0) {
  17. clearInterval(run);
  18. }
  19. this.text = "剩余 " + n + "s";
  20. if (this.text < "剩余 " + 0 + "s") {
  21. this.disabled = false;
  22. this.text = "重新获取";
  23. }
  24. }, 1000);
  25. }
  26. }
  27. };