ver_code.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <template>
  2. <div class="container">
  3. <el-input class="input" placeholder="请输入验证码" @input="$emit('change', $event)"></el-input>
  4. <button class="ver-btn" @click="clickBtn">{{remind}}</button>
  5. </div>
  6. </template>
  7. <script>
  8. let remindInit = '获取验证码'
  9. let max = 60
  10. let interval
  11. export default {
  12. data() {
  13. return {
  14. // 提示语
  15. remind: remindInit,
  16. // 读秒中
  17. running: false,
  18. max,
  19. }
  20. },
  21. methods: {
  22. clickBtn() {
  23. if(this.running) return
  24. this.$emit('click', () => {
  25. this.running = true
  26. this.remind = `${this.max}秒`
  27. interval = setInterval(() => {
  28. this.max -= 1
  29. if(this.max < 1) {
  30. clearInterval(interval)
  31. this.max = max
  32. this.remind = remindInit
  33. this.running = false
  34. } else {
  35. this.remind = `${this.max}秒`
  36. }
  37. }, 1000)
  38. })
  39. },
  40. }
  41. }
  42. </script>
  43. <style scoped>
  44. .container {
  45. position: relative;
  46. align-items: flex-start;
  47. }
  48. .input {
  49. width: 311px;
  50. height: 44px;
  51. }
  52. .ver-btn {
  53. position: absolute;
  54. top: 11px;
  55. right: 8px;
  56. color: var(--mainColor);
  57. font-size: 13px;
  58. }
  59. </style>