Skip to content

Input ​

简易介绍 ​

input 输入框组件,用于用户输入文本内容。mengyue-components 进行了封装并进行了 vitest 测试。 可以使用 <MYInput></MYInput> 来实现一个输入框。

基础用法 ​

使用 modelValue 绑定输入框的值。

代码演示
展开代码

输入类型 ​

通过 type 属性可以设置输入框的类型,如 text、password 等。

代码演示
展开代码

尺寸控制 ​

使用 width 和 height 属性可以自定义输入框的尺寸。

代码演示
展开代码

状态控制 ​

disabled ​

禁用输入框:

代码演示
展开代码

clearable ​

显示清除按钮:

代码演示
展开代码

showPassword ​

切换密码可见性:

代码演示
展开代码

输入限制 ​

长度限制 ​

使用 minLength 和 maxLength 限制输入长度:

代码演示
展开代码

字数统计 ​

使用 wordLimit 显示字数统计:

代码演示
0/20
展开代码

自定义颜色 ​

textColor ​

自定义文本颜色:

代码演示
展开代码

placeholderColor ​

自定义占位符颜色:

代码演示
展开代码

多行文本 ​

使用 tag="textarea" 实现多行文本输入:

代码演示
展开代码

组合使用 ​

多种属性组合使用:

代码演示
0/15
展开代码

API 参考 ​

Props ​

参数说明类型可选值默认值
type输入框类型stringtext/password等text
tag标签类型stringinput/textarea等input
width宽度string | number—100%
height高度string | number—30px
disabled是否禁用boolean—false
clearable是否可清除boolean—false
showPassword是否显示密码切换boolean—false
placeholder占位文本string—''
modelValue绑定值string—''
minLength最小输入长度number——
maxLength最大输入长度number | string——
wordLimit是否显示字数统计boolean—false
textColor文本颜色string支持16进制颜色或单词颜色—
placeholderColor占位符颜色string支持16进制颜色或单词颜色—

类型定义 ​

typescript
interface InputProps {
  type?: string;
  tag?: string;
  width?: string | number;
  height?: string | number;
  disabled?: boolean;
  clearable?: boolean;
  showPassword?: boolean;
  placeholder?: string;
  modelValue?: string;
  minLength?: number;
  maxLength?: number | string;
  wordLimit?: boolean;
  textColor?: string;
  placeholderColor?: string;
}

基于 MIT 协议