# Input 輸入框
文字 / 多行輸入。支援前後綴、清空、字數統計、maxlength 截斷與表單校驗聯動。
輸入框形態
<template>
<div class="demo-col" style="gap: 18px">
<div class="demo-row" style="gap: 12px; flex-wrap: wrap">
<LhInput v-model="text" placeholder="請輸入內容" clearable name="title" />
<LhInput v-model="text" prefix-icon="search" suffix-icon="close" placeholder="前後綴圖示" />
</div>
<div class="demo-row" style="gap: 12px; flex-wrap: wrap">
<LhInput v-model="secret" type="password" placeholder="密碼" autocomplete="new-password" />
<LhInput v-model="text" readonly placeholder="唯讀" />
<LhInput v-model="text" disabled placeholder="停用狀態" />
</div>
<div class="demo-row" style="gap: 12px; flex-wrap: wrap; align-items: center">
<LhInput v-model="text" size="small" placeholder="small" />
<LhInput v-model="text" size="medium" placeholder="medium" />
<LhInput v-model="text" size="large" placeholder="large" />
</div>
<div class="demo-row" style="gap: 12px; flex-wrap: wrap">
<LhInput v-model="poem" type="textarea" :rows="2" placeholder="多行文字(rows=2)" resize="vertical" />
<LhInput v-model="poem" type="textarea" autosize placeholder="自適應行高" />
</div>
<div class="demo-row" style="gap: 12px; flex-wrap: wrap">
<LhInput v-model="limited" :maxlength="20" show-word-limit placeholder="字數統計" />
<LhInput v-model="text" label="浮動標籤" placeholder="與 placeholder 互斥" />
</div>
<p class="demo-note">當前值:{{ text || '(空)' }}</p>
</div>
</template>
<script>
export default {
data: () => ({ text: '', secret: '', poem: '', limited: '' }),
}
</script>
# 標籤與浮動標籤
透過 label 提供控制項標籤,labelPosition 控制標籤位置,共五檔(預設 float):
float(預設):浮動標籤。label 在框內作佔位(與 placeholder 互斥),聚焦或有值時浮到控制項左上缺口並縮小;有值失焦後不回落,空值失焦才回落top/bottom:標籤靜態擺在控制項上方 / 下方(不浮動、不縮放)left/right:標籤與控制項同行內聯,位於控制項左 / 右側;labelWidth可為標籤定寬(僅這兩檔生效,數字按 px、字串原樣)
<template>
<!-- 浮动标签(默认 float):聚焦或有值时浮到左上缺口 -->
<LhInput v-model="value" label="姓名" />
<!-- 标签在上方 / 下方 -->
<LhInput v-model="value" label="姓名" label-position="top" />
<LhInput v-model="value" label="姓名" label-position="bottom" />
<!-- 标签在控件左 / 右侧;label-width 定宽,仅 left / right 生效 -->
<LhInput v-model="value" label="姓名" label-position="left" label-width="64px" />
<LhInput v-model="value" label="姓名" label-position="right" />
</template>
# Props
| 屬性 | 說明 | 類型 | 預設值 |
|---|---|---|---|
| v-model | 綁定值(model: modelValue/input) | string | — |
| type | 控制項類型 | 'text' \| 'textarea' \| 'password' \| … | 'text' |
| size | 尺寸 | 'small' \| 'medium' \| 'large' | 'medium' |
| placeholder | 佔位文案,缺省用語言包 | string | t('input.placeholder') |
| clearable | 顯示清空按鈕 | boolean | false |
| prefixIcon / suffixIcon | 前後綴圖示,取內建 LhIcon 圖示名 | string | — |
| maxlength / minlength | 原生長度限制 | number | — |
| showWordLimit | 顯示字數統計(需 maxlength) | boolean | false |
| autosize | textarea 自適應行高 | boolean \| {minRows,maxRows} | false |
| disabled / readonly | 停用 / 唯讀 | boolean | false |
| autofocus | 掛載時自動聚焦 | boolean | false |
| autocomplete | 原生 autocomplete | string | 'off' |
| nativeType | 原生 type(type=text 時生效) | string | 'text' |
| resize | textarea 縮放手柄方向 | 'none' \| 'both' \| 'horizontal' \| 'vertical' | — |
| name / form | 原生 name / form 屬性 | string | — |
| tabindex | 原生 tabindex | number \| string | — |
| inputStyle | 輸入元素行內樣式 | Record<string, string> | — |
| label | 浮動標籤(與 placeholder 互斥) | string | — |
| labelPosition | 標籤位置:float(預設,浮動標籤——聚焦/有值浮到左上缺口縮小,有值失焦不回落)/ top / bottom(靜態上下)/ left / right(同行內聯) | 'float' \| 'top' \| 'left' \| 'right' \| 'bottom' | 'float' |
| labelWidth | 標籤定寬,僅 left / right 生效(數字按 px,字串原樣) | string \| number | — |
| themeVars / bgPattern / sx | 主題覆蓋 | — | — |
# Events
| 事件 | 說明 | 回呼參數 |
|---|---|---|
| input | v-model 事件 | (val, e) |
| change | 值變化時觸發 | — |
| focus | 獲得焦點時觸發 | — |
| blur | 失去焦點時觸發 | — |
| clear | 清空時觸發 | — |
| keydown | 按鍵按下時觸發 | — |
# 表單聯動
置於 LhFormItem 內且校驗失敗時,原生控制項自動帶 aria-invalid="true"。
Copyright © 2024-2026 风默文学 | 宁ICP备2024006574号 |
苏公网安备32040002010537