Skip to content

Input 输入框

输入框组件用于通过键盘输入内容,是最基础的表单域包装。支持文本、密码、数字等多种输入类型。

平台差异说明

App(vue)App(nvue)H5小程序

基本使用

html
<template>
  <seeInput v-model="value" placeholder="请输入内容" />
</template>

<script setup>
import { ref } from 'vue'

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

输入类型

通过 type 属性设置输入类型,支持 textnumberpassworddigittelidcard

html
<template>
  <seeInput v-model="textValue" type="text" placeholder="文本输入" />
  <seeInput v-model="numberValue" type="number" placeholder="数字输入" />
  <seeInput v-model="passwordValue" type="password" placeholder="密码输入" />
  <seeInput v-model="digitValue" type="digit" placeholder="整数输入" />
  <seeInput v-model="telValue" type="tel" placeholder="电话输入" />
</template>

<script setup>
import { ref } from 'vue'

const textValue = ref('')
const numberValue = ref('')
const passwordValue = ref('')
const digitValue = ref('')
const telValue = ref('')
</script>

密码输入

设置 type="password" 可创建密码输入框,配合 showPassword 属性可切换密码可见性。

html
<template>
  <seeInput
    v-model="password"
    type="password"
    placeholder="请输入密码"
    show-password
  />
</template>

<script setup>
import { ref } from 'vue'

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

清除按钮

设置 isClearable 属性可显示清除按钮,一键清空输入内容。

html
<template>
  <seeInput
    v-model="value"
    placeholder="可清除的输入框"
    is-clearable
  />
</template>

<script setup>
import { ref } from 'vue'

const value = ref('可清除的内容')
</script>

字数统计

设置 isShowWordLimit 属性可显示字数统计,需配合 maxlength 使用。

html
<template>
  <seeInput
    v-model="value"
    placeholder="请输入内容"
    maxlength="20"
    is-show-word-limit
  />
</template>

<script setup>
import { ref } from 'vue'

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

前缀和后缀图标

通过 prefixIconsuffixIcon 属性设置前缀和后缀图标。

html
<template>
  <seeInput
    v-model="value"
    prefix-icon="search"
    placeholder="搜索内容"
  />
  <seeInput
    v-model="value"
    suffix-icon="calendar"
    placeholder="选择日期"
  />
</template>

插槽方式

使用 prefixsuffix 插槽自定义前缀和后缀内容。

html
<template>
  <seeInput v-model="value" placeholder="请输入网址">
    <template #prefix>
      <text>https://</text>
    </template>
    <template #suffix>
      <text>.com</text>
    </template>
  </seeInput>
</template>

格式化输入

通过 formatter 属性对输入内容进行格式化,例如手机号、银行卡号等。

html
<template>
  <seeInput
    v-model="phone"
    type="tel"
    placeholder="请输入手机号"
    :formatter="formatPhone"
    maxlength="13"
  />
</template>

<script setup>
import { ref } from 'vue'

const phone = ref('')

const formatPhone = (value) => {
  // 手机号格式化:xxx xxxx xxxx
  const cleaned = value.replace(/\D/g, '')
  const match = cleaned.match(/^(\d{3})(\d{0,4})(\d{0,4})$/)
  if (match) {
    return [match[1], match[2], match[3]].filter(Boolean).join(' ')
  }
  return cleaned
}
</script>

不同尺寸

通过 size 属性设置输入框尺寸,支持 smalldefaultlarge

html
<template>
  <seeInput v-model="value" size="small" placeholder="小尺寸" />
  <seeInput v-model="value" size="default" placeholder="默认尺寸" />
  <seeInput v-model="value" size="large" placeholder="大尺寸" />
</template>

禁用和只读

通过 isDisabledisReadonly 属性设置禁用和只读状态。

html
<template>
  <seeInput v-model="value" is-disabled placeholder="禁用状态" />
  <seeInput v-model="value" is-readonly placeholder="只读状态" />
</template>

无边框模式

设置 isBorderfalse 可隐藏输入框边框。

html
<template>
  <seeInput v-model="value" :is-border="false" placeholder="无边框输入框" />
</template>

API

Props

参数名说明类型默认值可选值平台差异
modelValue绑定值string | number''--
type输入类型string'text''text' / 'number' / 'password' / 'digit' / 'tel' / 'idcard'-
placeholder占位符string''--
isDisabled是否禁用booleanfalse--
isReadonly是否只读booleanfalse--
isClearable是否显示清除按钮booleanfalse--
maxlength最大输入长度number-1--
isShowWordLimit是否显示字数统计booleanfalse--
prefixIcon前缀图标string''--
suffixIcon后缀图标string''--
size尺寸string'default''small' / 'default' / 'large'-
isBorder是否显示边框booleantrue--
formatter输入格式化函数(value: string) => string---
name表单字段名string''--
showPassword是否显示密码切换按钮booleanfalse--

Events

事件名说明类型默认值可选值平台差异说明
onInput输入时触发(value: string | number) => void---
onFocus获取焦点时触发(event: FocusEvent) => void---
onBlur失去焦点时触发(event: FocusEvent) => void---
onClear点击清除按钮时触发() => void---
onChange值改变时触发(失去焦点或回车)(value: string | number) => void---
onConfirm点击完成按钮时触发(value: string | number) => void--小程序键盘确认

Slots

插槽名说明
prefix输入框头部内容
suffix输入框尾部内容

辽 ICP 备 2025070134 号