文本域 Textarea
多行纯文本编辑控件,适用于评论或反馈表单中的一段意见。
基本使用
可以用于多行输入。
代码事例
vue
<template>
<fk-textarea placeholder="商品衣诚" allow-clear/>
</template>文本域状态
文本域可以设置禁用和错误状态。
代码事例
vue
<template>
<fk-space direction="vertical" size="large" style="width: 100%">
<fk-textarea placeholder="Disabled status" disabled/>
<fk-textarea placeholder="Error status" error/>
</fk-space>
</template>字数统计
设置 max-length 可以限制最大字数,配合 show-word-limit 可以显示字数统计。
代码事例
vue
<template>
<fk-space direction="vertical" size="large" fill>
<fk-textarea placeholder="商品衣诚" :max-length="10" allow-clear show-word-limit />
<fk-textarea
placeholder="商品衣诚" :max-length="{length:10,errorOnly:true}" allow-clear
show-word-limit />
</fk-space>
</template>自适应高度
通过设置 auto-size,可以让文本框自适应输入内容。
代码事例
vue
<template>
<fk-textarea default-value="This is the contents of the textarea. This is the contents of the textarea. This is the contents of the textarea." auto-size show-word-limit :max-length="1000" />
<fk-textarea
default-value="This is the contents of the textarea. This is the contents of the textarea. This is the contents of the textarea." :auto-size="{
minRows:5,
maxRows:5
}" show-word-limit :max-length="1000" style="margin-top: 20px"/>
</template>API
<textarea> Props
| 参数名 | 描述 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| model-value (v-model) | 绑定值 | string | - | |
| default-value | 默认值(非受控状态) | string | '' | |
| placeholder | 提示文字 | string | - | |
| disabled | 是否禁用 | boolean | false | |
| error | 是否为错误状态 | boolean | false | |
| max-length | 输入值的最大长度,errorOnly 属性在 1.0.0 版本添加 | number | { length: number; errorOnly?: boolean } | 0 | |
| show-word-limit | 是否显示字数统计 | boolean | false | |
| allow-clear | 是否允许清空文本域 | boolean | false | |
| auto-size | 是否让文本框自适应内容高度 | boolean | AutoSize | false | |
| word-length | 字符长度的计算方法 | (value: string) => number | - | |
| word-slice | 字符截取方法,同 wordLength 一起使用 | (value: string, maxLength: number) => string | - | 1.0.0 |
<textarea> Events
| 事件名 | 描述 | 参数 |
|---|---|---|
| input | 用户输入时触发 | value: stringev: Event |
| change | 仅在文本框失焦时触发 | value: stringev: Event |
| clear | 点击清除按钮时触发 | ev: MouseEvent |
| focus | 文本框获取焦点时触发 | ev: FocusEvent |
| blur | 文本框失去焦点时触发 | ev: FocusEvent |
<textarea> Methods
| 方法名 | 描述 | 参数 | 返回值 | 版本 |
|---|---|---|---|---|
| focus | 使输入框获取焦点 | - | - | 1.0.0 |
| blur | 使输入框失去焦点 | - | - | 1.0.0 |