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>

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标签文案string—
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 属性。