Input 输入框
输入单行文本。
基础用法
使用 v-model 绑定输入内容。
查看代码收起代码
vue
<script setup lang="ts">
import { ZInput } from '@codex-proxy/ui'
import { ref } from 'vue'
const text = ref('')
</script>
<template>
<ZInput v-model="text" aria-label="名称" placeholder="请输入名称" />
</template>输入控件对照
切换尺寸,对比文本、标签、选择器和日期输入框。
禁用状态
设置 disabled 后,输入框无法聚焦或编辑。
查看代码收起代码
vue
<script setup lang="ts">
import { ZInput } from '@codex-proxy/ui'
import { Activity } from '@lucide/vue'
</script>
<template>
<ZInput model-value="12" type="number" aria-label="次数" disabled>
<template #prefix>
<Activity class="size-4" />
</template>
</ZInput>
</template>可清空
设置 clearable,悬停或聚焦时显示清空按钮。
查看代码收起代码
vue
<script setup lang="ts">
import { ZInput } from '@codex-proxy/ui'
import { ref } from 'vue'
const text = ref('请求工作台')
</script>
<template>
<ZInput v-model="text" aria-label="可清空" clearable />
</template>密码框
使用 show-password 切换密码的显示与隐藏。
查看代码收起代码
vue
<script setup lang="ts">
import { ZInput } from '@codex-proxy/ui'
import { ref } from 'vue'
const text = ref('example')
</script>
<template>
<ZInput v-model="text" aria-label="密码框" show-password />
</template>Input API
属性
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
validate-event | 随控件事件触发表单校验 | boolean | true |
v-model | 字符串值 | string | '' |
type | 原生输入类型 | string | 'text' |
placeholder | 占位文字 | string | '' |
size | 组件尺寸 | 'small' | 'default' | 'large' | 'default' |
disabled / clearable / show-password | 禁用、清空按钮、密码显隐按钮 | boolean | false |
id、name、required、readonly、autocomplete、ARIA 属性传给实际 input;class、style 作用于外层。自动填充默认关闭,可用 autocomplete 显式开启。输入法组合期间保留草稿,组合完成后更新模型
事件
update:modelValue(value: string):模型更新input(value: string):有效输入或清空change(value: string):原生 change 或清空clear():用户清空focus / blur(event: FocusEvent):原生焦点事件
插槽
prefix、suffix
实例
focus()、blur()、select()、clear()