Skip to content

Input 输入框 ​

基础用法 ​

vue
<template>
  <lh-input v-model="text" placeholder="请输入" />
  <lh-input v-model="text" type="textarea" :rows="3" autosize placeholder="多行" />
  <lh-input v-model="text" type="password" placeholder="密码" />
</template>

<script setup lang="ts">
import { ref } from 'vue'
const text = ref('')
</script>

占位样式(MP 必需) ​

小程序不支持 ::placeholder

微信小程序的 WXSS 不支持 ::placeholder 伪元素。占位样式请通过 prop 传入, 不要在 CSS 里写 ::placeholder(构建期门禁也会拦)。

vue
<lh-input placeholder="请输入" placeholder-style="color: #999; font-size: 13px" />
<!-- 或用类名 -->
<lh-input placeholder="请输入" placeholder-class="my-placeholder" />

带图标与状态 ​

vue
<template>
  <lh-input v-model="text" prefix-icon="search" placeholder="搜索" clearable />
  <lh-input v-model="text" suffix-icon="close" placeholder="后缀图标" />
  <lh-input v-model="text" state="error" placeholder="校验失败状态" />
  <lh-input v-model="text" :maxlength="20" show-word-limit placeholder="字数统计" />
</template>

标签位置 ​

label 现已真正渲染(此前 prop 声明未接线)。默认 float 浮动标签——聚焦或有值时浮到左上缺口; labelPosition 可切换为静态位置 top / bottom / left / right:

vue
<template>
  <!-- 默认:浮动标签(聚焦/有值浮到左上缺口) -->
  <lh-input v-model="text" label="用户名" />
  <!-- 上方 -->
  <lh-input v-model="text" label="用户名" label-position="top" />
  <!-- 下方 -->
  <lh-input v-model="text" label="用户名" label-position="bottom" />
  <!-- 左侧定宽(labelWidth 仅 left / right 生效) -->
  <lh-input v-model="text" label="用户名" label-position="left" :label-width="80" />
  <!-- 右侧 -->
  <lh-input v-model="text" label="用户名" label-position="right" />
</template>

【uni-app 差异】

  • float 的 size 档位垂直微调依赖 :has 选择器(WXSS 不支持),小程序端仅 medium 档精确、 其余档位 label 垂直位置略偏;静态位置(top / left / right / bottom)全端可用。
  • textarea + float 的浮起位置已由内联样式兜底,全端可用。

Props ​

属性说明类型默认值
modelValue (v-model)绑定值string—
type类型'text' | 'textarea' | 'password' | 'number' | 'email' | 'url' | 'tel' | 'date' | 'time''text'
size尺寸'small' | 'medium' | 'large'—
disabled禁用booleanfalse
readonly只读booleanfalse
placeholder占位文本string—
placeholderStyle占位内联样式(替代 ::placeholder)string—
placeholderClass占位类名(与 placeholderStyle 二选一)string—
maxlength最大长度number—
minlength最小长度number—
showWordLimit显示字数统计booleanfalse
clearable可清空booleanfalse
prefixIcon前缀图标LhIconName—
suffixIcon后缀图标LhIconName—
state校验状态'error' | 'success' | 'warning'—
name原生 name(供表单收集)string—
password密码模式booleanfalse
rowstextarea 行数number—
autosizetextarea 自适应高度(MP 的 auto-height)booleanfalse
label浮动标签(默认);配合 labelPosition 可切换位置string—
labelPosition标签位置'float' | 'top' | 'left' | 'right' | 'bottom''float'
labelWidth标签定宽(仅 left / right 生效;数字按 px,字符串原样)string | number—
customClass自定义类名string—
themeVars组件级主题变量Record<string, string>—
sx快速布局属性LhSxProps—

Events ​

事件说明回调参数
update:modelValue值变化(value: string)
input输入(取 event.detail.value)(value: string)
blur失焦—
focus聚焦—
clear清空—

与 Vue3 版的差异

autocomplete / autofocus / resize / form / tabindex / nativeType / inputStyle 在小程序无对应能力,本库不实现。autosize 走小程序 textarea 的 auto-height 属性。