Input 输入框
uni-appH5微信小程序App
跨端单行文本输入框,支持 v-model、类型、标签和禁用态。
何时使用
单行文本录入:用户名、搜索关键词、邮箱等。
何时不使用
多行长文本用 Textarea;从固定选项中选值用 Select。
本文档为 uni-app 端组件契约;Web 端同名组件 API 可能略有差异,请以对应包文档为准。下方手机预览实时运行 uni-app H5 演示。
Props
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
modelValue | string | "" | 绑定值,配合 v-model 使用 |
label | string | "" | 输入框上方标签文本 |
placeholder | string | "" | 占位文本 |
type | string:'text' | 'number' | 'password' | 'tel' | "text" | 原生 type 属性 |
disabled | boolean | false | 禁用(灰底) |
maxlength | number | -1 | 最大输入长度,传入后显示 已输/上限 计数 |
size | string:'sm' | 'md' | 'lg' | "md" | 尺寸;移动端建议 md 或 lg(触摸目标 ≥ 36px) |
readonly | boolean | false | 只读 |
clearable | boolean | false | 可清空;有值且聚焦/hover 时显示清空按钮 |
error | boolean | false | 错误态,红色边框 |
Events
| 名称 | 载荷 | 说明 |
|---|---|---|
update:modelValue | string | 输入时同步绑定值 |
input | string | - |
change | string | 失焦或回车时值发生变化才触发 |
focus | Event | 聚焦时触发 |
blur | Event | 失焦时触发 |
clear | void | 点击清空按钮时触发,同时 update:modelValue 为空串 |
示例
基础用法
vue
<Input v-model="name" label="昵称" placeholder="请输入昵称" />类型与密码
vue
<Input v-model="email" label="邮箱" type="email" placeholder="name@example.com" />
<Input v-model="value1" label="密码" type="password" placeholder="请输入密码" style="margin-top:10px" />禁用与字数
vue
<Input v-model="value2" label="禁用" disabled />
<Input v-model="value3" label="限 5 字" :maxlength="5" placeholder="最多输入 5 个字" style="margin-top:10px" />尺寸 / 清空 / 错误态
vue
<Input v-model="value4" size="sm" placeholder="小号" clearable />
<Input v-model="value5" size="lg" placeholder="大号" clearable style="margin-top:10px" />
<Input v-model="value6" error placeholder="错误态:红色边框" style="margin-top:10px" />