Skip to content

Input 输入框

通用的文本输入组件,支持前缀、后缀图标和清除按钮。

基础用法

vue
<script setup>
import { ref } from 'vue'
const value = ref('')
</script>

<template>
  <MInput v-model="value" placeholder="请输入内容..." />
</template>

可清空

vue
<template>
  <MInput v-model="value" placeholder="可清空输入框" clearable />
</template>

禁用与只读

vue
<template>
  <MInput placeholder="禁用状态" disabled />
  <MInput placeholder="只读状态" readonly />
</template>

错误状态

vue
<template>
  <MInput v-model="value" placeholder="错误状态" error />
</template>

前缀/后缀插槽

vue
<template>
  <MInput v-model="value" placeholder="搜索...">
    <template #prefix>
      <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
      </svg>
    </template>
  </MInput>
</template>

Props 属性

属性名类型默认值说明
modelValuestring | number-绑定值(v-model)
typestring'text'原生 input 类型
placeholderstring''占位文本
disabledbooleanfalse是否禁用
readonlybooleanfalse是否只读
clearablebooleanfalse是否显示清除按钮
errorbooleanfalse错误状态样式

Events 事件

事件名参数说明
update:modelValue(value: string)输入值变化时触发
focus(event: FocusEvent)获得焦点时触发
blur(event: FocusEvent)失去焦点时触发
enter(event: KeyboardEvent)按下回车键时触发
clear-点击清除按钮时触发

Slots 插槽

插槽名说明
prefix输入框前置内容
suffix输入框后置内容

暴露的方法

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

Released under the MIT License.