Skip to content

Input 输入框

基础表单文本输入组件,支持文本、数字、密码显隐切换、手机号区号前缀、短信验证码倒计时、错误校验与多行文本域等丰富功能。


代码示例

1. 基础用法 (Basic)

使用 v-model 双向绑定输入文本,设置 clearable 显示一键清除按键。

vue
<template>
  <mu-input v-model="username" label="用户名" placeholder="请输入用户名" clearable />
  <mu-input v-model="email" label="邮箱地址" prefix-icon="mail" placeholder="请输入邮箱地址" clearable />
</template>

2. 密码输入与明暗切换 (Password)

设置 type="password" 自动开启密码掩码与右侧眼睛点击明文/密文切换。

vue
<template>
  <mu-input
    v-model="password"
    type="password"
    label="登录密码"
    prefix-icon="lock"
    placeholder="请输入密码"
    clearable
  />
</template>

3. 手机号与验证码倒计时 (Phone & Code)

设置 phone-prefix 显示 +86 区号前缀;设置 send-code 开启 60 秒原生短信验证码倒计时胶囊按钮。

vue
<template>
  <mu-input
    v-model="phone"
    type="tel"
    label="手机号码"
    required
    phone-prefix
    placeholder="请输入手机号"
    clearable
  />

  <mu-input
    v-model="code"
    type="code"
    label="短信验证码"
    required
    prefix-icon="shield"
    send-code
    placeholder="请输入 6 位验证码"
    @send-code="handleSendCode"
  />
</template>

<script setup>
const handleSendCode = () => {
  console.log('触发发送验证码')
}
</script>

4. 标签位置对齐 (Label Position)

设置 label-position="left" 实现 Label 标题在左侧与输入框同行排列。

vue
<template>
  <mu-input v-model="realname" label="真实姓名" label-position="left" required />
  <mu-input v-model="company" label="公司名称" label-position="left" />
</template>

5. 错误提示与字符计数器 (Error & Counter)

设置 errorerror-message 显示标红校验警告,设置 countermaxlength 实时显示字数限制。

vue
<template>
  <mu-input
    v-model="account"
    label="账号名"
    error
    error-message="账号名不能包含非法特殊字符"
  />

  <mu-input
    v-model="sign"
    label="个人签名"
    :maxlength="20"
    counter
  />
</template>

6. 多行文本域 (Textarea)

设置 type="textarea" 转换为多行富文本输入区域。

vue
<template>
  <mu-input
    v-model="remark"
    type="textarea"
    label="详细备注说明"
    placeholder="请输入备注说明"
    :maxlength="200"
    counter
  />
</template>

API 属性说明 (Props)

参数名说明类型可选值默认值
v-model绑定当前输入的文本值String | Number-''
type输入框类型Stringtext | number | digit | tel | password | code | textarea'text'
shape围栏边框形状Stringradius | square | round'radius'
label输入框标题String-''
labelPosition标题布局位置Stringtop | left'top'
labelWidth左侧标题宽度String-'160rpx'
required是否展示必填红色星号Booleantrue | falsefalse
placeholder占位文本String-'请输入'
disabled是否禁用Booleantrue | falsefalse
clearable是否显示一键清除图标Booleantrue | falsefalse
maxlength最大输入字符数Number--1
counter是否显示字数限制计数器Booleantrue | falsefalse
error是否标红错误状态Booleantrue | falsefalse
errorMessage底部错误提示文本String-''
prefixIcon前置矢量图标名称String-''
suffixIcon后置矢量图标名称String-''
filled是否开启背景填充模式Booleantrue | falsefalse
autoHeight多行文本域是否自动增高Booleantrue | falsefalse
showPasswordToggle密码框模式下是否显示小眼睛明暗切换Booleantrue | falsetrue
codeText倒计时按键文案String-'发送验证码'
useKeyboard是否调用组件内置虚拟键盘Booleantrue | falsefalse
keyboardMode虚拟键盘模式Stringnumber | card | car'number'
keyboardTitle虚拟键盘标题String-''
phonePrefix是否显示 +86 手机号区号前缀Booleantrue | falsefalse
sendCode是否显示验证码倒计时按键Booleantrue | falsefalse
codeSeconds验证码倒计时秒数Number-60

插槽说明 (Slots)

插槽名说明
prefix自定义输入框内部最左侧元素
suffix自定义输入框内部最右侧元素
label自定义标题 Label 区域

事件说明 (Events)

事件名说明回调参数
update:modelValue输入文本改变时触发(value: String)
input原生输入时触发(value: String)
focus获取焦点时触发(event: Event)
blur失去焦点时触发(event: Event)
clear点击清除图标时触发-
send-code点击发送验证码时触发-

实例方法 (Expose Methods)

方法名说明
startCountdown()手动启动发送验证码倒计时

基于 MIT 协议开源发行

H5 模拟器 (input)☀️🔄