Skip to content

Input 输入框 ​

单行输入框:支持左侧标签、前后缀、清除按钮、禁用 / 只读、聚焦态、三种外观与四档尺寸。

平台支持 ​

Web微信小程序AndroidiOSHarmonyOS
5.385.385.385.385.38
Input 输入框
加载中…

基础用法 ​

html
<vapor-input v-model="value" placeholder="请输入内容" clearable></vapor-input>

带标签与后缀 ​

html
<vapor-input v-model="value" label="用户名" label-width="64" suffix="元"></vapor-input>

前后缀图标 ​

图标名取 vapor-icon 的图标名:

html
<vapor-input v-model="value" prefix-icon="user" prefix="账号"></vapor-input>
<vapor-input v-model="value" suffix-icon="eye" clearable></vapor-input>

输入类型 ​

type 支持 text / number / digit / idcard / tel / email / url / search / nickname。number 只允许数字,digit 允许小数点(Web 端自动带 inputmode="decimal" 小数键盘)。

密码框 ​

password 为 true 时输入内容以掩码显示(内置 input 的 password 属性,uni-app x 的 type 合法值不含 password)。passwordToggle 默认开启,显示「明文 / 密文」切换眼睛图标。

html
<vapor-input v-model="pwd" password password-toggle></vapor-input>

外观样式 ​

variant 支持 outlined(描边)/ filled(浅灰底)/ underline(下划线)。聚焦时边框不换色——边框颜色全程不变,聚焦反馈由原生光标承担,因此滑动页面、划过输入框都不会误亮闪烁;常态边框色可用 themeColor 覆盖。

属性 ​

属性类型默认值说明
modelValuestring''绑定值,配合 v-model 使用
typestring'text'输入类型
passwordbooleanfalse是否为密码类型(掩码显示)
passwordTogglebooleantrue是否显示「明文 / 密文」切换眼睛图标
placeholderstring''占位文案
disabledbooleanfalse是否禁用
readonlybooleanfalse是否只读:不可编辑,外观保持正常(与 disabled 的区别是不置灰)
clearablebooleanfalse是否显示清除按钮(有值且非禁用 / 只读时显示)
maxlengthnumber-1最大输入长度,-1 表示不限制
focusbooleanfalse是否自动聚焦
confirmTypestring'done'键盘确认按钮文案
adjustPositionbooleantrue软键盘弹出时是否自动上推页面
cursorColorstring''光标颜色,留空使用系统默认
size'mini' | 'small' | 'medium' | 'large''medium'尺寸档
variant'outlined' | 'filled' | 'underline''outlined'外观样式:描边 / 浅灰底 / 下划线
labelstring''左侧标签文案
labelWidthnumber | string0标签固定宽度,数字按 px,带单位原样透传;0 或空自适应
prefixstring''前缀文本(配合 prefix 插槽使用)
prefixIconstring''前缀图标名,取 vapor-icon 的图标名
suffixstring''后缀文本(配合 suffix 插槽使用)
suffixIconstring''后缀图标名,取 vapor-icon 的图标名
themeColorstring''常态边框颜色,留空使用默认边框色;聚焦时不换色
customClassstring''根节点样式类
customInputClassstring''输入框样式类
customLabelClassstring''标签样式类
customPrefixClassstring''前缀样式类
customSuffixClassstring''后缀样式类
customClearClassstring''清除按钮样式类

事件 ​

事件说明参数
change值变化(每次输入 / 清除触发,与 v-model 同步)value: string
input输入时触发UniInputEvent
focus获得焦点UniInputFocusEvent
blur失去焦点UniInputBlurEvent
confirm点击键盘确认按钮UniInputConfirmEvent
clear点击清除按钮-

插槽 ​

prefix(输入框左侧内容)、suffix(输入框右侧内容)。

组件方法 ​

通过 ref 调用:focus()(获取焦点)、blur()(失去焦点)、clear()(清空输入值)。

说明 ​

  • 清除按钮与前后缀图标:叉号与前后缀图标都由 vapor-icon 渲染(close 字形),配色走图标的信息色(--vapor-icon-info-color),不再单独提供 --vapor-input-clear-color 变量。
  • 图标尺寸:跟随 size 档位(前后缀 13 / 14 / 17 / 20,清除叉号 14 / 15 / 18 / 20),比同档文字略大一档。
  • 只读实现:内置 input 没有 readonly 属性,组件以 disabled 实现只读,因此只读态下部分平台仍可能把文字显示为系统禁用色。
  • 聚焦态时机:聚焦态只由原生 focus / blur 事件驱动。由于聚焦不再改变边框颜色,App 端该事件约 190ms 的派发延迟不再影响视觉反馈。
  • 基座依赖:输入框基于内置 input 组件,App 端属 uni-form 模块。若提示「uni-form 模块不存在」,需重新制作包含 uni-form 的自定义调试基座。