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 屬性。