Skip to content

Input 输入框

通过鼠标或键盘输入内容,是最基础的表单域的包装。

基础用法

通过 v-model 双向绑定输入框的值。

vue
<template>
  <ImInput v-model="value" placeholder="基础使用" />
</template>

<script setup lang="ts">
import { ref } from 'vue';
const value = ref('');
</script>

前缀后缀

在输入框中添加前缀或后缀图标。

https
.com

插槽方式

https.com
vue
<template>
  <ImInput
    v-model="value"
    placeholder="基础使用"
    prefix="https"
    suffix=".com" />

  <ImInput v-model="value" placeholder="基础使用">
    <template #prefix>https</template>
    <template #suffix>.com</template>
  </ImInput>
</template>

前置后置

设置 prependappend 属性可以分别在输入框前置和后置内容。

Prepend
Append

插槽方式

https
.com
vue
<template>
  <ImInput prepend="Prepend" clearable append="Append" v-model="value" />
  <ImInput v-model="value" placeholder="基础使用">
    <template #prepend>https</template>
    <template #append>.com</template>
  </ImInput>
</template>

禁用

设置 disabled 属性可以禁用输入框。

vue
<template>
  <ImInput disabled clearable v-model="value" />
</template>

清除

设置 clearable 属性可以显示一个清空按钮,点击可清除输入框内容。

vue
<template>
  <ImInput clearable v-model="value" />
</template>

密码

设置类型 password 可以将输入框设置为密码类型,此时输入内容会被隐藏。

vue
<template>
  <ImInput type="password" v-model="value" />
</template>

尺寸

设置 size 属性可以控制输入框的大小。 48

vue
<template>
  <ImInput size="48" v-model="value" />
</template>

API

字段名类型描述
modelValuestring | number | any绑定的值
disabledboolean是否禁用,默认为false
readonlyboolean是否只读,默认为false
placeholderstring输入框占位符
typestring输入框类型
namestring输入框名称
idstring输入框ID
maxlengthnumber最大长度
minlengthnumber最小长度
maxnumber最大值
minnumber最小值
stepnumber步长
patternstring输入验证正则表达式
requiredboolean是否必填,默认为false
autocompletestring自动完成提示信息
autofocusboolean页面加载时是否自动聚焦,默认为false
tabindexnumbertab索引
precisionnumber数值精度
sizenumber | string输入框大小
prefixstring输入框前缀
suffixstring输入框后缀
clearableboolean是否可清除内容,默认为false
passwordEyeboolean密码输入框是否显示眼睛图标,默认为false
showWordCountboolean是否显示字数统计,默认为false
prependstring输入框前置内容
appendstring输入框后置内容

基于 MIT 协议发布