Skip to content

Textarea 文本域

文本域用于输入多行文本,支持自定义高度、行数和自动调整高度。

基础用法

最基本的文本域,通过 v-model 双向绑定数据。

当前值: (空)
vue
<template>
  <u-input type="textarea" v-model="value" placeholder="请输入内容"></u-input>
  <div>当前值: {{ value || '(空)' }}</div>
</template>

<script setup>
  import { ref } from 'vue';
  const value = ref('');
</script>

自定义行数

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

vue
<template>
  <u-input type="textarea" :rows="2" v-model="value1" placeholder="2 行"></u-input>
  <u-input type="textarea" :rows="4" v-model="value2" placeholder="4 行"></u-input>
  <u-input type="textarea" :rows="6" v-model="value3" placeholder="6 行"></u-input>
</template>

<script setup>
  import { ref } from 'vue';
  const value1 = ref('');
  const value2 = ref('');
  const value3 = ref('');
</script>

最大长度

通过 maxlength 属性限制输入的最大字符数。

vue
<template>
  <u-input type="textarea" :maxlength="100" v-model="value" placeholder="最多输入 100 个字符"></u-input>
</template>

<script setup>
  import { ref } from 'vue';
  const value = ref('');
</script>

禁用和只读

vue
<template>
  <u-input type="textarea" disabled v-model="value1" placeholder="禁用状态"></u-input>
  <u-input type="textarea" readonly v-model="value2" placeholder="只读状态"></u-input>
</template>

<script setup>
  import { ref } from 'vue';
  const value1 = ref('这是禁用状态的文本');
  const value2 = ref('这是只读状态的文本');
</script>

API

属性说明类型默认值
modelValue绑定值string''
type设置为 textareastring必填 'textarea'
placeholder占位文本string-
rows行数number | string3
maxlength最大长度number | string-
disabled是否禁用booleanfalse
readonly是否只读booleanfalse