Skip to content
Promote Your Product

InputCode Verification Code Input

💡 Component: my-input-code

Verification code input component, used for obtaining email and SMS verification codes.

Local import

import { defineAsyncComponent } from 'vue'
const MyInputCode = defineAsyncComponent(() => import('/@/components/my-input-code/index.vue'))

Email Verification Code

const state = reactive({
  form: {
    email: '',
    code: '',
    codeId: '',
  },
})

// Validate email
const validateEmail = (callback: Function) => {
  formRef.value.validateField('email', (isValid: boolean) => {
    if (!isValid) {
      emailRef.value?.focus()
      return
    }
    callback?.()
  })
}

// Send verification code
const onSend = (codeId: string) => {
  state.form.codeId = codeId
}
<MyInputCode v-model="form.code" :email="form.email" :validate="validateEmail" @send="onSend" />

SMS Verification Code

const state = reactive({
  form: {
    mobile: '',
    code: '',
    codeId: '',
  },
})

// Validate mobile number
const validateMobile = (callback: Function) => {
  formRef.value.validateField('mobile', (isValid: boolean) => {
    if (!isValid) {
      phoneRef.value?.focus()
      return
    }
    callback?.()
  })
}

// Send verification code
const onSend = (codeId: string) => {
  state.form.codeId = codeId
}
 <MyInputCode v-model="form.code" :mobile="form.mobile" :validate="validateMobile" @send="onSend" />

Props

PropDescriptionTypeDefaultAccepted Values
maxlengthMaximum lengthNumber6-
secondsCountdown after getting the code, in secondsNumber60-
maxlengthMaximum lengthNumber6-
startTextCountdown start textStringGet Code-
changeTextCountdown in-progress textStrings sec resend-
endTextCountdown end textStringResend Code-
mobileMobile numberString--
emailEmail addressString--
validateValidation methodFunction--