Skip to content

Input 输入框

基本用法

输入框的基本用法。

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

const input = ref("");
</script>

<template>
  <l-space>
    <l-input placeholder="请输入内容" allow-clear v-model="input" width="300px" />
    <l-input
      placeholder="请输入内容"
      default-value="默认值"
      allow-clear
      v-model="input"
      width="300px"
    />
  </l-space>
</template>

输入框状态

可以通过status设置, 包括success, warning, error三种状态。

也可以直接设置success, warning, error属性。

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

const input = ref("");
</script>

<template>
  <l-space wrap>
    <l-input placeholder="请输入内容" v-model="input" width="300px" success />
    <l-input placeholder="请输入内容" v-model="input" width="300px" status="success" />
    <l-input placeholder="请输入内容" v-model="input" width="300px" warning />
    <l-input placeholder="请输入内容" v-model="input" width="300px" status="warning" />
    <l-input placeholder="请输入内容" v-model="input" width="300px" danger />
    <l-input placeholder="请输入内容" v-model="input" width="300px" status="danger" />
    <l-input placeholder="禁用" v-model="input" width="300px" disabled />
  </l-space>
</template>

输入框尺寸

可以通过size属性设置输入框的尺寸,包括small, medium, large三种尺寸。

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

const input = ref("");
</script>

<template>
  <l-space wrap>
    <l-input placeholder="请输入内容" size="small" v-model="input" width="300px" />
    <l-input placeholder="请输入内容" size="medium" v-model="input" width="300px" />
    <l-input placeholder="请输入内容" size="large" v-model="input" width="300px" />
  </l-space>
</template>

前缀与后缀

通过指定prefixsuffix插槽, 可以在输入框内添加前缀和后缀。

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

const input = ref("");
</script>

<template>
  <l-space>
    <l-input placeholder="请输入内容" allow-clear v-model="input" width="300px">
      <template #prefix><l-icon icon="user" /></template>
    </l-input>
    <l-input placeholder="请输入内容" allow-clear v-model="input" width="300px">
      <template #suffix><l-icon icon="info-circle" /></template>
    </l-input>
  </l-space>
</template>

前置、后置标签

通过指定prependappend插槽, 可以在输入框前后添加元素。

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

const input = ref("");
</script>

<template>
  <l-space>
    <l-input placeholder="请输入内容" allow-clear v-model="input" width="300px">
      <template #prepend>+86</template>
    </l-input>
    <l-input placeholder="请输入内容" allow-clear v-model="input" width="300px">
      <template #append>RMB</template>
    </l-input>
  </l-space>
</template>

密码输入框

可以通过设置type属性为password来实现密码输入框。

通过showPassword属性设置是否显示密码,默认不显示。

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

const input = ref("");
</script>

<template>
  <l-space>
    <l-input
      type="password"
      placeholder="请输入内容"
      show-password
      allow-clear
      v-model="input"
      width="300px"
    />
  </l-space>
</template>

文本域

可以通过设置type属性为textarea来实现文本域。

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

const input = ref("");
</script>

<template>
  <l-space>
    <l-input placeholder="请输入内容" type="textarea" v-model="input" width="300px" />
  </l-space>
</template>

Input API

Props

属性名描述类型默认值
type原生 input 类型 textpasswordtextareastringtext
modelValue绑定值string | number-
size输入框尺寸small | medium | largemedium
status输入框状态success | warning | error-
defalutValue输入框默认值string | number-
placeholder输入框占位符string-
disabled是否禁用booleanfalse
readonly是否只读booleanfalse
success成功状态booleanfalse
warning警告状态booleanfalse
error错误状态booleanfalse
showPassword是否显示密码booleanfalse
clearable是否显示清除按钮booleanfalse
width输入框宽度string-
style输入框样式CSSProperties-

Events

事件名描述回调参数
inputinput 值变化-
change仅当 modelValue 值变化, 输入框失去焦点或用户按 Enter 时触发-
focus输入框获得焦点-
blur输入框失去焦点-
clear点击clearable属性生成的清除按钮-

Slots

插槽名描述
prefix输入框前缀内容
suffix输入框后缀内容
prepend输入框前置内容
append输入框后置内容

Exposed

名称描述
ref输入框实例
clear清除输入框内容
focus聚焦输入框
blur失焦输入框
select选中输入框内容

鲁ICP备2024093316号