<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-model | string | - | 设置文本域的内容 (双向绑定) |
<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 | 类型 | 默认值 | 描述 |
---|---|---|---|
placeholder | string | - | 设置文本域占位符文本 |
<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 | 类型 | 默认值 | 描述 |
---|---|---|---|
showCount | boolean | false | 是否显示字数统计 |
<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 | 类型 | 默认值 | 描述 |
---|---|---|---|
maxlength | number | 140 | 设置文本最大长度 |
<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 | 类型 | 默认值 | 描述 |
---|---|---|---|
disabled | boolean | false | 设置文本域是否为禁用状态 |
<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 | 类型 | 默认值 | 描述 |
---|---|---|---|
readonly | boolean | false | 设置文本域是否为只读状态 |
<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 | 类型 | 默认值 | 描述 |
---|---|---|---|
clearable | boolean | false | 是否显示清空按钮 |
<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 | 类型 | 默认值 | 描述 |
---|---|---|---|
autoHeight | boolean | false | 是否自动调整文本域高度 |
<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-model | string | - | 详见 Controlled 文本控制 |
placeholder | string | - | 详见 Placeholder 占位符 |
size | {Size} | medium | 详见 Size 尺寸 |
showCount | boolean | false | 详见 ShowCount 显示字数 |
maxlength | number | 140 | 详见 MaxLength 最大长度 |
disabled | boolean | false | 详见 Disabled 禁用 |
readonly | boolean | false | 详见 Readonly 只读 |
clearable | boolean | false | 详见 Clearable 可清空 |
autoHeight | boolean | false | 详见 AutoHeight 自动高度 |
Emits
事件名 | 参数 | 描述 |
---|---|---|
input | (event: { value: string }) | 当用户输入时触发 |
focus | (event: { value: string }) | 当文本域获得焦点时触发 |
blur | (event: { value: string }) | 当文本域失去焦点时触发 |
clear | () | 当点击清空按钮时触发 |
交互
正在完善中,敬请期待!😊