Skip to content

Input 输入框

通过鼠标或键盘输入字符

基础用法

<script lang="ts" setup>
import { ref } from 'vue'
import SiInput from '@/components/Input/Input.vue'
const input = ref('')
</script>

<template>
  <div style="width: 240px;">
    <SiInput
      v-model="input"
      placeholder="Please input"
    />
  </div>
</template>

禁用状态

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

<script lang="ts" setup>
import { ref } from 'vue'
import SiInput from '@/components/Input/Input.vue'

const input = ref('')
</script>

<template>
  <div style="width: 240px;">
    <SiInput
      v-model="input"
      placeholder="Please input"
      disabled
    />
  </div>
</template>

一键清空

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

<script lang="ts" setup>
import { ref } from 'vue'
import SiInput from '@/components/Input/Input.vue'

const input = ref('')
</script>

<template>
  <div style="width: 240px;">
    <SiInput
      v-model="input"
      placeholder="Please input"
      clearable
    />
  </div>
</template>

密码框

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

<script lang="ts" setup>
import { ref } from 'vue'
import SiInput from '@/components/Input/Input.vue'

const input = ref('')
</script>

<template>
  <div style="width: 240px;">
    <SiInput
      v-model="input"
      placeholder="Please input"
      show-password
    />
  </div>
</template>

带图标的输入框

可以在输入框中前置或后置一个元素,通常是标签或按钮。

Using slots

<script lang="ts" setup>
import { ref } from 'vue'
import SiInput from '@/components/Input/Input.vue'
import Icon from '@/components/Icon/Icon.vue'

const input3 = ref('')
const input4 = ref('')
</script>

<template>
  <div style="width: 240px;">
    <span>Using slots</span>
    <hr>
    <SiInput v-model="input3" placeholder="Pick a date">
      <template #suffix>
        <Icon icon="fa-calendar" />
      </template>
    </SiInput>
    <hr>
    <SiInput v-model="input4" placeholder="Type something">
      <template #prefix>
        <Icon icon="fa-magnifying-glass" />
      </template>
    </SiInput>
  </div>
</template>

复合型输入框

可以在输入框中前置或后置一个元素,通常是标签或按钮。

Http://

.com
<script lang="ts" setup>
import { ref } from 'vue'
import SiInput from '@/components/Input/Input.vue'
import Icon from '@/components/Icon/Icon.vue'

const input1 = ref('')
const input2 = ref('')
</script>

<template>
  <div style="width: 240px;">
    <SiInput v-model="input1" placeholder="Please input">
      <template #prepend>
        Http://
      </template>
    </SiInput>
    <hr>
    <SiInput v-model="input2" placeholder="Please input">
      <template #append>
        .com
      </template>
    </SiInput>
  </div>
</template>

文本域

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

<script lang="ts" setup>
import { ref } from 'vue'
import SiInput from '@/components/Input/Input.vue'

const textarea = ref('')
</script>

<template>
  <div style="width: 240px;">
    <SiInput
      v-model="textarea"
      placeholder="Please input"
      type="textarea"
    />
  </div>
</template>

尺寸

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



<script lang="ts" setup>
import { ref } from 'vue'
import SiInput from '@/components/Input/Input.vue'

const input1 = ref('')
const input2 = ref('')
const input3 = ref('')
</script>

<template>
  <div style="width: 240px;">
    <SiInput
      v-model="input1"
      size="large"
      placeholder="Please Input"
    />
    <hr>
    <SiInput
      v-model="input2"
      placeholder="Please Input"
    />
    <hr>
    <SiInput
      v-model="input3"
      size="small"
      placeholder="Please Input"
    />
  </div>
</template>

API

Attributes

属性名说明类型默认值
type类型string原生 input 类型text
v-model绑定值string / number
disabled是否禁用booleanfalse
size输入框尺寸,只在 type 不为 'textarea' 时有效small / large
autocomplete原生 autocomplete 属性stringoff
placeholder输入框占位文本string
clearable是否显示清除按钮,只有当 type 不是 textarea时生效booleanfalse
autofocus原生属性,自动获取焦点booleanfalse
parser指定从格式化器输入中提取的值。(仅当 type 是"text"时才起作用)Function
show-password是否显示切换密码图标booleanfalse
form原生属性string
readonly只读属性booleanfalse

Events

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

Slots

插槽名说明
prefix输入框头部内容,只对非 type="textarea" 有效
suffix输入框尾部内容,只对非 type="textarea" 有效
prepend输入框前置内容,只对非 type="textarea" 有效
append输入框后置内容,只对非 type="textarea" 有效

Exposes

名称说明类型
refHTML元素 input 或 textareaobject

基于 MIT 许可发布