OTPInput.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <script setup lang="ts">
  2. import VOtpInput from 'vue3-otp-input'
  3. const emit = defineEmits(['onComplete'])
  4. const data = defineModel<string>()
  5. const refOtp = ref()
  6. function onComplete(value: string) {
  7. emit('onComplete', value)
  8. }
  9. function clearInput() {
  10. refOtp.value?.clearInput()
  11. }
  12. defineExpose({
  13. clearInput,
  14. })
  15. </script>
  16. <template>
  17. <VOtpInput
  18. ref="refOtp"
  19. v-model:value="data"
  20. input-classes="otp-input"
  21. :num-inputs="6"
  22. input-type="number"
  23. should-auto-focus
  24. should-focus-order
  25. @on-complete="onComplete"
  26. />
  27. </template>
  28. <style lang="less">
  29. .dark {
  30. .otp-input {
  31. border: 1px solid rgba(255, 255, 255, 0.2) !important;
  32. &:focus {
  33. outline: none;
  34. border: 2px solid #1677ff !important;
  35. }
  36. }
  37. }
  38. </style>
  39. <style scoped lang="less">
  40. :deep(.otp-input) {
  41. width: 40px;
  42. height: 40px;
  43. padding: 5px;
  44. margin: 0 10px;
  45. font-size: 20px;
  46. border-radius: 4px;
  47. border: 1px solid rgba(0, 0, 0, 0.3);
  48. text-align: center;
  49. background-color: transparent;
  50. &:focus {
  51. outline: none;
  52. border: 2px solid #1677ff;
  53. }
  54. &::-webkit-inner-spin-button,
  55. &::-webkit-outer-spin-button {
  56. -webkit-appearance: none;
  57. margin: 0;
  58. }
  59. }
  60. </style>