Skip to content

Code

A verification code input component that supports custom length, type, mask mode, cursor animation, and more.

  • Supports custom verification code length
  • Supports box, line, middleLine, and bottomLine styles
  • Supports password mask mode
  • Supports cursor blinking animation
  • Supports custom keyboard type

Notice

This component may have slight behavioral differences across platforms. Please refer to the actual rendered result.

Platform Differences

App (vue)App (nvue)H5Mini Program

Basic Usage

  • Bind the input value via v-model.
  • Defaults to 4-digit verification code with auto-focus enabled.
html
<see-code v-model="code" @on-complete="handleComplete" />

<script lang="ts" setup>
import { ref } from 'vue';
const code = ref('');

const handleComplete = (value) => {
  console.log('Verification code completed', value);
};
</script>

6-Digit Code

  • Set the verification code length via length, which defaults to 4.
html
<see-code v-model="code" :length="6" @on-complete="handleComplete" />

<script lang="ts" setup>
import { ref } from 'vue';
const code = ref('');

const handleComplete = (value) => {
  console.log('Verification code completed', value);
};
</script>

Different Types

  • Set the input style via type, supporting box (box), line (baseline), middleLine (middle line), and bottomLine (underline).
html
<see-code v-model="code1" type="box" />
<see-code v-model="code2" type="line" />
<see-code v-model="code3" type="middleLine" />
<see-code v-model="code4" type="bottomLine" />

<script lang="ts" setup>
import { ref } from 'vue';
const code1 = ref('');
const code2 = ref('');
const code3 = ref('');
const code4 = ref('');
</script>

Mask Mode

  • Enable password mask mode by setting isMask to true. Input characters are displayed as dots.
  • Suitable for scenarios where the verification code needs to be hidden.
html
<see-code v-model="code" isMask />

<script lang="ts" setup>
import { ref } from 'vue';
const code = ref('');
</script>

Cursor Animation

  • Enable cursor blinking animation by setting isCursor to true, which is enabled by default.
html
<see-code v-model="code" isCursor />

<script lang="ts" setup>
import { ref } from 'vue';
const code = ref('');
</script>

Custom Gap

  • Set the gap between input fields via gap in px, which defaults to 10.
html
<see-code v-model="code" :gap="20" />

<script lang="ts" setup>
import { ref } from 'vue';
const code = ref('');
</script>

API

Props

ParameterDescriptionTypeDefaultOptional Values
modelValueInput valuestring''-
lengthVerification code lengthnumber4-
isFocusWhether to auto-focusbooleantrue-
isDisabledWhether disabledbooleanfalse-
isReadonlyWhether readonlybooleanfalse-
sizeSize'small' | 'default' | 'large''default'-
typeInput style type'box' | 'line' | 'middleLine' | 'bottomLine''box'-
isMaskWhether to enable mask modebooleanfalse-
gapGap between input fields (px)number10-
nameForm field namestring''-
keyboardKeyboard type'number' | 'text''number'-
isCursorWhether to show cursorbooleantrue-

Events

EventDescriptionCallback Parameters
onChangeTriggered when the input value changesvalue: string
onCompleteTriggered when the verification code input is completevalue: string
onFocusTriggered when the input field gains focusevent: Event
onBlurTriggered when the input field loses focusevent: Event

Expose

MethodDescriptionParametersReturn Value
focusFocus the input field-void
getValueGet the current input value-string

Liao ICP No. 2025070134