Skip to content

TInput / 输入框

Input is the most basic data entry component in forms. Supports multiple types, prefix/suffix icons and text, validation states, and labels. / 输入框是表单中最基础的数据录入组件,支持多种类型、前后缀图标/文本、验证状态和标签提示。

Props / 属性

PropType / 类型Default / 默认值Description / 说明
typestring'text'Input type (text, password, number, etc.)
placeholderstringPlaceholder text
size'sm' | 'lg'Size
disabledbooleanfalseDisabled
readonlybooleanfalseReadonly
maxlengthnumberMax length
labelstringLabel text
hintstringHint text
validation'valid' | 'invalid'Validation state
errorbooleanfalseShow error state
error-messagestringError message
prependIconIconPrefix icon
appendIconIconSuffix icon
prependTextstringPrefix text
appendTextstringSuffix text
roundedbooleanfalseRounded style
flushbooleanfalseBorderless style
blockbooleanfalseFull width
wrapperClassstringOuter container class (e.g. "mb-3")

v-model

v-modelType / 类型Description / 说明
v-modelstringTwo-way binding / 双向绑定

Events / 事件

EventDescription / 说明
@update:modelValuev-model update
@changeValue changed
@focus / @blurFocus / Blur

Basic Usage / 基础用法

vue
<script setup lang="ts">
import { TInput } from '@gulcc/tabler-vue'
</script>

<template>
  <TInput v-model="name" placeholder="Enter name / 请输入姓名" />
  <TInput v-model="email" type="email" placeholder="Enter email / 请输入邮箱" />
  <TInput v-model="password" type="password" placeholder="Password / 密码" />
</template>

Advanced Usage / 进阶场景

vue
<script setup lang="ts">
import { TInput } from '@gulcc/tabler-vue'
import { IconSearch, IconUser } from '@tabler/icons-vue'

const email = ref('')
const isValidEmail = computed(() => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email.value))
</script>

<template>
  <!-- With label and validation / 带标签和验证 -->
  <TInput
    v-model="email"
    label="Email / 邮箱"
    placeholder="Enter email / 请输入邮箱"
    :error="!!email && !isValidEmail"
    error-message="Invalid email / 邮箱格式不正确"
    wrapper-class="mb-3"
  />

  <!-- With icons / 带图标 -->
  <TInput
    v-model="search"
    placeholder="Search / 搜索..."
    :prepend-icon="IconSearch"
  />

  <!-- With prefix/suffix text / 带前后缀文本 -->
  <TInput
    v-model="url"
    placeholder="Enter address / 请输入地址"
    prepend-text="https://"
    append-text=".com"
  />

  <!-- With hint / 带提示 -->
  <TInput
    v-model="phone"
    label="Phone / 手机号"
    hint="11 digits / 请输入11位手机号码"
    maxlength="11"
  />
</template>

Tips / 避坑指南

  • TInput uses inheritAttrs: false — pass container classes via wrapperClass prop, not directly on the component
  • Both :error="true" and error-message="xxx" are required to show validation errors
  • Icons are passed via prependIcon / appendIcon props (component reference), NOT in the default slot
  • Use wrapper-class="mb-3" for form spacing — TInput has no bottom margin by default