Skip to content

Input 输入框

通过鼠标或键盘输入字符

基础文本框

<script setup>
import { ref } from 'vue'
const test = ref('')
</script>
<template>
  <vk-input v-model="test" placeholder="基础文本框,请输入" />
  <span>{{test}}</span>
</template>

禁用文本框

通过 disabled 属性指定是否禁用 input 组件

<script setup>
import { ref } from 'vue'
const test = ref('some text')
</script>
<template>
  <vk-input v-model="test" disabled />
</template>

尺寸

使用 size 属性改变输入框大小。 除了默认大小外,还有另外两个选项: large, small

<script setup>
import { ref } from 'vue'
const test = ref('')
</script>
<template>
  <div class="size-holder">
    <vk-input v-model="test" placeholder="大的 Input" size="large">
    </vk-input>
    <vk-input v-model="test" placeholder="普通的 Input">
    </vk-input>
    <vk-input v-model="test" placeholder="小的 Input" size="small">
    </vk-input>
  </div>
</template>
<style scoped>
.size-holder {
  display: flex;
  align-items: center;
}
</style>

复合型输入框

可以在输入框前置或后置一个元素,通常是标签或按钮。可以使用 prependappend 插槽。 要在输入框中添加前后元素,可以使用 prefixsuffix 插槽。

Https://
.com
<script setup>
import { ref } from 'vue'
const test = ref('')
</script>
<template>
  <vk-input v-model="test" placeholder="prepend append">
    <template #prepend>Https://</template>
    <template #append>.com</template>
  </vk-input>

  <vk-input v-model="test" placeholder="prefix suffix">
    <template #prefix>
      <vk-icon icon="fa-user" />
    </template>
    <template #suffix>
      <vk-icon icon="fa-user" />
    </template>
  </vk-input>
</template>

Textarea

用于输入多行文本信息可缩放的输入框。 添加 type="textarea" 属性来将 input 元素转换为原生的 textarea 元素。

<script setup>
import { ref } from 'vue'
const test = ref('')
</script>
<template>
  <vk-input v-model="test" placeholder="可以是一个 Textarea" type="textarea">
  </vk-input>
</template>

密码文本框

使用 show-password 属性即可得到一个可切换显示隐藏的密码框

<script setup>
import { ref } from 'vue'
const test = ref('')
</script>
<template>
  <vk-input v-model="test" placeholder="密码文本框,可以切换" showPassword/>
</template>

清空文本框

使用 clearable 属性即可得到一个可一键清空的输入框

<script setup>
import { ref } from 'vue'
const test = ref('')
</script>
<template>
  <vk-input v-model="test" clearable placeholder="输入字符以后可以点击清空"/>
</template>

Input API

Input Attributes

属性名说明类型默认值
type输入类型enum - 'text'| 'textarea'| 'password'text
model-value / v-model绑定值'string' \/ 'number'
size输入框尺寸,只在 type 不为 'textarea' 时有效enum - 'large'| 'small'
placeholder输入框占位文本string
clearable是否显示清除按钮,只有当 type 不是 textarea时生效booleanfalse
disabled按钮是否为禁用状态booleanfalse
showPassword是否显示切换密码图标booleanfalse
autofocus原生 autofocus 属性booleanfalse
readonly原生 readonly 属性,是否只读booleanfalse
form原生属性string
autocomplete原生 autocomplete 属性stringoff

Input Events

事件名说明类型
change仅当 modelValue 改变时,当输入框失去焦点或用户按Enter时触发Function
blur当选择器的输入框失去焦点时触发Function
focus当选择器的输入框获得焦点时触发Function
input在 Input 值改变时触发Function
clear在点击由 clearable 属性生成的清空按钮时触发Function

Input Exposes

方法名说明类型
refHTML元素 inputtextareaobject