Skip to content

Textarea 文本域

文本域组件用于多行文本输入,支持自动高度、字数统计、清除等功能。

平台差异说明

App(vue)App(nvue)H5小程序

基本使用

html
<template>
  <seeTextarea v-model="value" placeholder="请输入内容" />
</template>

<script setup>
import { ref } from 'vue'

const value = ref('')
</script>

设置行数

通过 rows 属性设置文本域默认显示行数。

html
<template>
  <seeTextarea v-model="value" :rows="5" placeholder="5行高度的文本域" />
</template>

<script setup>
import { ref } from 'vue'

const value = ref('')
</script>

自动高度

设置 isAutoHeight 属性,文本域高度会根据内容自动调整。

html
<template>
  <seeTextarea
    v-model="value"
    placeholder="输入内容,高度会自动调整"
    is-auto-height
  />
</template>

<script setup>
import { ref } from 'vue'

const value = ref('')
</script>

字数统计

设置 isShowWordLimit 属性可显示字数统计,需配合 maxlength 使用。

html
<template>
  <seeTextarea
    v-model="value"
    placeholder="请输入内容"
    maxlength="200"
    is-show-word-limit
  />
</template>

<script setup>
import { ref } from 'vue'

const value = ref('')
</script>

清除按钮

设置 isClearable 属性可显示清除按钮,一键清空输入内容。

html
<template>
  <seeTextarea
    v-model="value"
    placeholder="可清除的文本域"
    is-clearable
  />
</template>

<script setup>
import { ref } from 'vue'

const value = ref('可清除的内容')
</script>

禁用和只读

通过 isDisabledisReadonly 属性设置禁用和只读状态。

html
<template>
  <seeTextarea v-model="value" is-disabled placeholder="禁用状态" />
  <seeTextarea v-model="value" is-readonly placeholder="只读状态" />
</template>

<script setup>
import { ref } from 'vue'

const value = ref('')
</script>

不同尺寸

通过 size 属性设置文本域尺寸,支持 smalldefaultlarge

html
<template>
  <seeTextarea v-model="value" size="small" placeholder="小尺寸" />
  <seeTextarea v-model="value" size="default" placeholder="默认尺寸" />
  <seeTextarea v-model="value" size="large" placeholder="大尺寸" />
</template>

无边框模式

设置 isBorderfalse 可隐藏文本域边框。

html
<template>
  <seeTextarea v-model="value" :is-border="false" placeholder="无边框文本域" />
</template>

键盘确认键

通过 confirmType 属性设置键盘右下角确认键的文字。

html
<template>
  <seeTextarea v-model="value" confirm-type="done" placeholder="确认键为'完成'" />
</template>

API

Props

参数名说明类型默认值可选值平台差异
modelValue绑定值string''--
placeholder占位符string''--
isDisabled是否禁用booleanfalse--
isReadonly是否只读booleanfalse--
maxlength最大输入长度number-1--
isShowWordLimit是否显示字数统计booleanfalse--
rows默认显示行数number3--
isAutoHeight是否自动高度booleanfalse--
isBorder是否显示边框booleantrue--
isClearable是否显示清除按钮booleanfalse--
size尺寸string'default''small' / 'default' / 'large'-
name表单字段名string''--
confirmType键盘确认键类型string'done''done' / 'send' / 'search' / 'next' / 'go'小程序

Events

事件名说明类型默认值可选值平台差异说明
onInput输入时触发(value: string) => void---
onFocus获取焦点时触发(event: FocusEvent) => void---
onBlur失去焦点时触发(event: FocusEvent) => void---
onClear点击清除按钮时触发() => void---
onChange值改变时触发(失去焦点)(value: string) => void---
onConfirm点击完成按钮时触发(value: string) => void--小程序键盘确认
onLineChange行数变化时触发(event: { height: number, heightRpx: number, lineCount: number }) => void---

Expose

属性名说明类型
validateStatus当前校验状态Ref<'success' | 'error' | 'validating' | ''>
validateMessage当前校验信息Ref<string>
focus聚焦输入框() => void
blur失焦输入框() => void
isDisabled是否禁用() => boolean
isFocused是否聚焦() => boolean

辽 ICP 备 2025070134 号