Skip to content

H5预览

APP下载

Input 输入框

cl-input 组件基于 uni-app 的 input 组件,提供了丰富的输入功能和样式定制能力。

参数

参数说明类型可选值默认值
pt样式穿透配置PassThrough
modelValue绑定值string""
type输入框类型string"text" | "number" | "idcard" | "digit" | "tel" | "safe-password" | "nickname""text"
prefixIcon前缀图标名称string
suffixIcon后缀图标名称string
password是否为密码类型booleanfalse
autofocus是否自动聚焦booleanfalse
placeholder输入框为空时的占位符文本string"请输入"
placeholderClass占位符文本的样式类名string""
border是否显示边框booleanfalse
disabled是否禁用输入框booleanfalse
readonly是否为只读状态booleanfalse
clearable是否可清空内容booleanfalse
maxlength最大输入长度限制number140
cursorSpacing指定光标与键盘的距离(单位:px)number5
confirmHold点击键盘确认按钮时是否保持键盘不收起booleanfalse
confirmType设置键盘右下角按钮的文字string"done" | "go" | "next" | "search" | "send"done
adjustPosition键盘弹起时,是否自动上推页面booleantrue
holdKeyboard是否保持键盘不收起booleanfalse

插槽

插槽说明
prepend在输入框前面插入的内容
append在输入框后面插入的内容

事件

事件说明
input输入内容时触发
change输入内容改变时触发
focus输入框获得焦点时触发
blur输入框失去焦点时触发
confirm点击键盘确认按钮时触发
clear点击清空按钮时触发
keyboardheightchange键盘高度发生变化时触发

PassThrough

样式穿透配置,用于自定义组件内部元素的样式。

参数说明类型
className组件根元素样式string
inner输入框配置PassThroughProps
prefixIcon前缀图标配置ClIconProps
suffixIcon后缀图标配置ClIconProps

示例

基本用法

最简单的输入框用法:

html
<cl-input></cl-input>

数字输入

通过设置 typenumber 来限制只能输入数字:

html
<cl-input type="number"></cl-input>

密码输入

通过设置 password 属性来隐藏输入内容:

html
<cl-input password></cl-input>

可清除内容

通过设置 clearable 属性来显示清空按钮:

html
<cl-input clearable></cl-input>

使用前后插槽

通过插槽可以在输入框前后添加自定义内容:

html
<cl-input>
  <template #append>
    <cl-button
      type="primary"
      size="small"
      icon="send-plane-fill"
      :pt="{
			className: 'ml-2'
		}"
    ></cl-button>
  </template>
</cl-input>

<cl-input>
  <template #prepend>
    <cl-button
      type="primary"
      size="small"
      icon="search-line"
      :pt="{
			className: 'mr-2'
		}"
      @tap="toAlert"
    ></cl-button>
  </template>
</cl-input>

自定义样式

通过 pt 属性可以自定义组件样式:

vue
<cl-input
  :pt="{
    className: '!bg-sky-100 !border-sky-700',
    inner: {
      className: '!text-sky-700',
    },
  }"
></cl-input>