Input 输入框
单行输入框:支持左侧标签、前后缀、清除按钮、禁用 / 只读、聚焦态、三种外观与四档尺寸。
平台支持
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| 5.38 | 5.38 | 5.38 | 5.38 | 5.38 |
加载中…
基础用法
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 覆盖。
属性
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
modelValue | string | '' | 绑定值,配合 v-model 使用 |
type | string | 'text' | 输入类型 |
password | boolean | false | 是否为密码类型(掩码显示) |
passwordToggle | boolean | true | 是否显示「明文 / 密文」切换眼睛图标 |
placeholder | string | '' | 占位文案 |
disabled | boolean | false | 是否禁用 |
readonly | boolean | false | 是否只读:不可编辑,外观保持正常(与 disabled 的区别是不置灰) |
clearable | boolean | false | 是否显示清除按钮(有值且非禁用 / 只读时显示) |
maxlength | number | -1 | 最大输入长度,-1 表示不限制 |
focus | boolean | false | 是否自动聚焦 |
confirmType | string | 'done' | 键盘确认按钮文案 |
adjustPosition | boolean | true | 软键盘弹出时是否自动上推页面 |
cursorColor | string | '' | 光标颜色,留空使用系统默认 |
size | 'mini' | 'small' | 'medium' | 'large' | 'medium' | 尺寸档 |
variant | 'outlined' | 'filled' | 'underline' | 'outlined' | 外观样式:描边 / 浅灰底 / 下划线 |
label | string | '' | 左侧标签文案 |
labelWidth | number | string | 0 | 标签固定宽度,数字按 px,带单位原样透传;0 或空自适应 |
prefix | string | '' | 前缀文本(配合 prefix 插槽使用) |
prefixIcon | string | '' | 前缀图标名,取 vapor-icon 的图标名 |
suffix | string | '' | 后缀文本(配合 suffix 插槽使用) |
suffixIcon | string | '' | 后缀图标名,取 vapor-icon 的图标名 |
themeColor | string | '' | 常态边框颜色,留空使用默认边框色;聚焦时不换色 |
customClass | string | '' | 根节点样式类 |
customInputClass | string | '' | 输入框样式类 |
customLabelClass | string | '' | 标签样式类 |
customPrefixClass | string | '' | 前缀样式类 |
customSuffixClass | string | '' | 后缀样式类 |
customClearClass | string | '' | 清除按钮样式类 |
事件
| 事件 | 说明 | 参数 |
|---|---|---|
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的自定义调试基座。