input 输入框
优质
小牛编辑
130浏览
2023-12-01
import { Input } from 'feui'; components: { [Input.name]: Input }
代码演示
基础用法
<fe-group> <fe-input title='value' v-model="value" placeholder="我是占位符"></fe-input> </fe-group>
不可用状态
<fe-group title="不可用状态"> <fe-input title='value' disabled v-model="disabledValue"></fe-input> </fe-group>
设置最大值最小值
<fe-group title="set min=2 and max=5"> <fe-input title="2-5个字符" placeholder="" :min="2" :max="5"></fe-input> </fe-group>
设置is-type
属性
<fe-group title="请输入姓名"> <fe-input title="姓名" name="username" placeholder="请输入姓名" is-type="china-name"> </fe-input> </fe-group> <fe-group title="设置 keyboard=number,is-type=china-mobile"> <fe-input title="手机号码" name="mobile" placeholder="请输入手机号码" keyboard="number" is-type="china-mobile"> </fe-input> </fe-group> <fe-group title="set is-type=email"> <fe-input title="邮箱" name="email" placeholder="请输入邮箱地址" is-type="email"> </fe-input> </fe-group> <fe-group title="is-type传入function"> <fe-input title="输入验证" :is-type="be2333" placeholder="必须输入2333"></fe-input> </fe-group>
不显示清除按钮
<fe-group title="不显示清除按钮"> <fe-input title="message" required placeholder="我是可爱的占位符" :show-clear="false" autocapitalize="characters"> </fe-input> </fe-group>
使用icon代替title
<fe-group title="使用icon代替title"> <fe-input title="必须输入2333" :is-type="be2333" placeholder="必须输入2333"> <img slot="label" style="padding-right:10px;display:block;" src="http://temp.im/42x42/34AADC/fff" width="24" height="24"> </fe-input> </fe-group>
输入格式化
<fe-group title="mask"> <fe-input title="手机号码格式化" mask="999 9999 9999" v-model="maskValue" :max="13" is-type="china-mobile"> </fe-input> <fe-cell title="value" :value="maskValue"></fe-cell> <fe-input title="(99) 9-999" mask="(99) 9-999" v-model="maskValue2" :max="10" placeholder="76幢1单元305"> </fe-input> </fe-group>
API
参数 | 说明 | 类型 | 默认值 | 可选值 |
---|---|---|---|---|
title | label文字 | String | - | - |
placeholder | 站位提示 | String | - | - |
value | 表单值,使用v-model 绑定 | String | - | - |
disabled | 是否禁用填写 | Boolean | false | false ,true |
type | input的type 属性,目前支持 text ,number ,email ,password ,tel | String | text | - |
is-type | 内置验证器,支持email ,china-name ,china-mobile ,同样也支持直接传函数, 需要同步返回一个对象 {valid:true} 或者 {valid:false, msg:错误信息} | String ,Function | - | - |
required | 是否必值,如果不禁用验证,当没有填写时会在右侧显示错误icon | Boolean | false | false ,true |
show-clear | 是否显示清除icon | Boolean | false | false ,true |
min | 最小输入字符限制 | Number | - | - |
max | 最大输入字符限制,等同于maxlength | Number | - | - |
debounce | debounce 用以限制on-change 事件触发。如果你需要根据用户输入做 ajax 请求,建议开启以节省无效请求和服务器资源,单位为毫秒 | Number | - | - |
placeholder-align | placeholder 对其方式 | String | left | left ,right ,center |
text-align | 值对齐方式 | String | left | left ,right ,center |
label-width | label 宽度,权重比 group 的 labelWidth 高 | String | - | - |
mask | 值格式化,依赖于 vanilla-masker,其中 9 表示数字,A 表示大写字母,S 表示数字或者字母 | String | - | - |
should-toast-error | 是否在点击错误图标时用 toast 的形式显示错误 | Boolean | true | false ,true |
- | - | - | - | - |
Slots
Slot名 | 说明 | 备注 |
---|---|---|
label | 用于自定义label (即 title)部分内容,比如使用icon | - |
restricted-label | 用于自定义label 部分,和slot=label 不同的是,该slot宽度受到父组件group 的限制 | - |
right | 用以在输入框右边显示内容,比如验证码图片,单位,切换密码显示方式等 | - |
- | - | - |
Events
事件名 | 参数 | 说明 | 备注 |
---|---|---|---|
on-focus | value, $event | input的focus 事件 | - |
on-blur | value, $event | input的blur 事件 | - |
on-enter | value, $event | input输入完成后点击enter(确认) 事件 | - |
on-change | value | 输入值变化时触发。如果你使用了debounce ,那么触发将不会是实时的。 | - |
on-click-error-icon | error | 点击错误图标时触发 | - |
- | - | - | - |
Methods
方法名 | 参数 | 说明 | 备注 |
---|---|---|---|
focus | - | 手动设置input 获得焦点 | - |
blur | - | 手动设置input 失去焦点 | - |
reset | value = '' | 重置输入框值,清除错误信息 | - |
- | - | - | - |