Skip to content

Input 输入框

用于单行文本输入,并提供搜索、密码和组合输入等扩展形态。

基础用法

vue
<template>
  <x-input v-model="value" placeholder="请输入" allow-clear />
</template>

<script setup lang="ts">
import { ref } from 'vue';

const value = ref('');
</script>

前缀与后缀

vue
<template>
  <x-input v-model="value" placeholder="请输入">
    <template #prefix>https://</template>
    <template #suffix>.com</template>
  </x-input>
</template>

前置与后置标签

vue
<template>
  <x-input v-model="value" placeholder="请输入域名">
    <template #prepend>https://</template>
    <template #append>.com</template>
  </x-input>
</template>

关联组件

vue
<template>
  <x-input-search placeholder="搜索" />
  <x-input-password placeholder="密码" />
  <x-input-group>
    <x-input placeholder="省" />
    <x-input placeholder="市" />
  </x-input-group>
</template>

按需导入

ts
import { Input, InputSearch, InputPassword, InputGroup } from 'x-next';

Input Props

参数说明类型默认值
modelValue绑定值string-
defaultValue默认值,非受控模式string''
size输入框尺寸'mini' | 'small' | 'medium' | 'large'跟随全局配置
allowClear是否允许清空booleanfalse
disabled是否禁用booleanfalse
readonly是否只读booleanfalse
error是否为错误状态booleanfalse
placeholder占位提示string-
maxLength最大长度,支持仅提示错误number | { length: number; errorOnly?: boolean }0
showWordLimit是否显示字数统计booleanfalse
wordLength字符长度计算方法(value: string) => number-
wordSlice超长时的截取方法(value: string, maxLength: number) => string-
inputAttrs内部 input 元素属性object-

Input Events

事件名说明回调参数
update:modelValue值更新时触发value
input用户输入时触发value, event
change失焦或按下回车且值变化时触发value, event
press-enter按下回车时触发event
clear点击清除按钮时触发event
focus获取焦点时触发event
blur失去焦点时触发event

Input Slots

插槽名说明
prefix前缀内容
suffix后缀内容
prepend前置标签
append后置标签

Input Methods

方法说明
focus使输入框获取焦点
blur使输入框失去焦点