Skip to content

Input ​

Demo ​

Input Cross-platform Example and Preview

H5 LiveInteractive browser runtime
States

Basic Usage ​

vue
<script setup lang="ts">
import { ref } from 'vue'

const value = ref('')
</script>

<template>
  <VInput v-model:value="value" placeholder="Type here" />
  <VInput default-value="Default content" />
</template>

Clearable And Word Limit ​

vue
<template>
  <VInput v-model:value="value" clearable placeholder="Type here" />
  <VInput v-model:value="value" :max-length="20" show-word-limit />
  <VInput v-model:value="value" clearable clear-trigger="always" />
</template>

Formatting ​

vue
<script setup lang="ts">
const trim = (value: string) => value.trim()
const digits = (value: string) => value.replace(/\D/g, '')
</script>

<template>
  <VInput v-model:value="value" :formatter="trim" format-trigger="onBlur" />
  <VInput v-model:value="phone" :formatter="digits" :max-length="11" />
</template>

Textarea ​

vue
<template>
  <VInput type="textarea" :rows="3" placeholder="Notes" />
  <VInput type="textarea" :autosize="{ minRows: 2, maxRows: 5 }" />
</template>

Alignment, Affixes, And State ​

vue
<template>
  <VInput label="Name" placeholder="Type a name" />
  <VInput prefix-icon="Search" suffix-icon="Done" />
  <VInput align="right" value="Right aligned" />
  <VInput readonly value="Readonly content" />
  <VInput disabled value="Disabled content" />
  <VInput invalid error-message="Enter a valid value" />
</template>

Props ​

PropTypeDefaultDescription
valuestring | undefinedundefinedControlled value
defaultValuestring''Initial uncontrolled value
placeholderstring | undefinedundefinedPlaceholder text
typestring'text'Input type; textarea renders a textarea
size'sm' | 'md' | 'lg''md'Input size
align'left' | 'center' | 'right''left'Text alignment
disabledbooleanfalseDisabled state
readonlybooleanfalseReadonly state
invalidbooleanfalseInvalid state
clearablebooleanfalseShow a clear control
clearTrigger'focus' | 'always''focus'When the clear control is visible
maxLengthnumber | stringundefinedMaximum input length
showWordLimitbooleanfalseShow word count
formatter(value: string) => stringundefinedValue formatter
formatTrigger'onInput' | 'onBlur''onInput'Formatter trigger
rowsnumber | stringundefinedTextarea rows
autosizeboolean | { minRows?: number; maxRows?: number }falseTextarea autosize
labelstringundefinedLeft label
labelWidthnumber | stringundefinedLabel width
prefixIconstringundefinedPrefix content
suffixIconstringundefinedSuffix content
errorMessagestringundefinedError message

Controlled empty values on Weapp

Weapp cannot distinguish an omitted value from :value="undefined"; both use defaultValue. Pass value="" for a controlled empty value.

Native Weapp props

name, inputId, className, customStyle, ARIA, form, focus, cursor, and keyboard props are forwarded to the native control. H5 accepts native attrs directly.

Events ​

EventPayloadDescription
update:valuestringValue update
valueChangestringValue change
clearMouseEventClear control click
focusFocusEventFocus
blurFocusEventBlur

Slots ​

SlotDescription
labelCustom label
prefixCustom prefix
suffixCustom suffix

Data Attributes ​

AttributeDescription
data-sizeCurrent size
data-alignCurrent alignment
data-clearableClearable state
data-focusedFocus state
data-invalidInvalid state
data-readonlyReadonly state
data-disabledDisabled state