Textarea 文本域

用于输入多行文本的文本域组件

<script setup lang="ts">
import { ref } from 'vue'

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

<template>
  <div class="p-4 w-full">
    <SkTextarea v-model="value" />
  </div>
</template>

用法

Controlled 文本控制

Prop类型默认值描述
v-modelstring-设置文本域的内容 (双向绑定)
<script setup lang="ts">
import { ref } from 'vue'

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

<template>
  <div class="flex flex-col p-4 gap-3 w-full">
    <SkTextarea v-model="value" placeholder="请输入内容" />
    <div class="text-sm text-secondary">
      当前值: {{ value }}
    </div>
  </div>
</template>

Placeholder 占位符

Prop类型默认值描述
placeholderstring-设置文本域占位符文本
<script setup lang="ts">
import { ref } from 'vue'

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

<template>
  <div class="p-4 w-full">
    <SkTextarea v-model="value" placeholder="请输入您的意见和建议..." />
  </div>
</template>

Size 尺寸

Prop类型默认值描述
size{Size}medium设置文本域的尺寸大小
Size描述
small小型
medium中型
large大型
<script setup lang="ts">
import { ref } from 'vue'

const smallValue = ref('')
const mediumValue = ref('')
const largeValue = ref('')
</script>

<template>
  <div class="flex flex-col p-4 gap-3 w-full">
    <SkTextarea v-model="smallValue" size="small" placeholder="小尺寸文本域" />
    <SkTextarea v-model="mediumValue" size="medium" placeholder="中尺寸文本域" />
    <SkTextarea v-model="largeValue" size="large" placeholder="大尺寸文本域" />
  </div>
</template>

ShowCount 显示字数

Prop类型默认值描述
showCountbooleanfalse是否显示字数统计
<script setup lang="ts">
import { ref } from 'vue'

const value1 = ref('')
const value2 = ref('这是一些示例文本')
</script>

<template>
  <div class="flex flex-col p-4 gap-3 w-full">
    <SkTextarea v-model="value1" :show-count="false" placeholder="不显示字数统计" />
    <SkTextarea v-model="value2" :show-count="true" :max-length="100" placeholder="显示字数统计" />
  </div>
</template>

Maxlength 最大长度

Prop类型默认值描述
maxlengthnumber140设置文本最大长度
<script setup lang="ts">
import { ref } from 'vue'

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

<template>
  <div class="flex flex-col p-4 gap-3 w-full">
    <SkTextarea v-model="value" :maxlength="50" show-count placeholder="最大长度 50 字符" />
  </div>
</template>

Disabled 禁用

Prop类型默认值描述
disabledbooleanfalse设置文本域是否为禁用状态
<script setup lang="ts">
import { ref } from 'vue'

const normalValue = ref('')
const disabledValue = ref('这是禁用状态的文本域')
</script>

<template>
  <div class="flex flex-col p-4 gap-3 w-full">
    <SkTextarea v-model="normalValue" placeholder="正常状态" />
    <SkTextarea v-model="disabledValue" disabled placeholder="禁用状态" />
  </div>
</template>

Readonly 只读

Prop类型默认值描述
readonlybooleanfalse设置文本域是否为只读状态
<script setup lang="ts">
import { ref } from 'vue'

const value = ref('这是只读内容,无法编辑')
</script>

<template>
  <div class="flex flex-col p-4 gap-3 w-full">
    <SkTextarea placeholder="普通文本域" />
    <SkTextarea v-model="value" placeholder="只读文本域" readonly />
  </div>
</template>

Clearable 可清空

Prop类型默认值描述
clearablebooleanfalse是否显示清空按钮
<script setup lang="ts">
import { ref } from 'vue'

const value = ref('这是一些示例文本')
</script>

<template>
  <div class="flex p-4 w-full">
    <SkTextarea v-model="value" clearable placeholder="可清空的文本域" />
  </div>
</template>

AutoHeight 自动高度

Prop类型默认值描述
autoHeightbooleanfalse是否自动调整文本域高度
<script setup lang="ts">
import { ref } from 'vue'

const value = ref('这是一个自动高度的文本域示例。\n当您输入更多内容时,\n文本域会自动调整高度。\n继续输入更多文本来查看效果。')
</script>

<template>
  <div class="flex flex-col p-4 gap-3 w-full">
    <SkTextarea v-model="value" :auto-height="true" placeholder="自动高度文本域" />
  </div>
</template>

接口

Props

属性名类型默认值描述
v-modelstring-详见 Controlled 文本控制
placeholderstring-详见 Placeholder 占位符
size{Size}medium详见 Size 尺寸
showCountbooleanfalse详见 ShowCount 显示字数
maxlengthnumber140详见 MaxLength 最大长度
disabledbooleanfalse详见 Disabled 禁用
readonlybooleanfalse详见 Readonly 只读
clearablebooleanfalse详见 Clearable 可清空
autoHeightbooleanfalse详见 AutoHeight 自动高度

Emits

事件名参数描述
input(event: { value: string })当用户输入时触发
focus(event: { value: string })当文本域获得焦点时触发
blur(event: { value: string })当文本域失去焦点时触发
clear()当点击清空按钮时触发

交互

正在完善中,敬请期待!😊