Skip to content

Textarea 文本域

介绍

文本框内输入或编辑文字,支持限制输入数量。

基础用法

html
<template>
  <nut-textarea v-model="value" />
</template>
<script>
import { ref } from 'vue';
export default {
  setup() {
    const value = ref('');
    return { value };
  },
};
</script>

显示字数统计

html
<template>
  <nut-textarea v-model="value" limit-show max-length="20" />
</template>

高度自定义,拉伸

html
<template>
  <nut-textarea v-model="value" autosize />
</template>

只读、禁用

html
<template>
  <nut-textarea readonly model-value="textarea 只读状态" />
  <nut-textarea disabled model-value="textarea 禁用状态" />
</template>

API

Props

参数说明类型可选值默认值
v-model输入值,支持双向绑定string--
textarea-style 1.7.3文本域自定义样式StyleValue--
textarea-class 1.7.3文本域自定义类名ClassType--
placeholder设置占位提示文字string-请输入内容
placeholder-style 1.6.9指定 placeholder 的样式string--
placeholder-class 1.6.9指定 placeholder 的样式类string-textarea-placeholder
max-length限制最长输入字符string / number--
rowstextarea的高度,优先级高于autosize属性 仅支持 H5string / number-2
limit-showtextarea是否展示输入字符。须配合max-length使用boolean-false
autosize是否自适应内容高度,也可传入对象,
{ maxHeight: 200, minHeight: 100 },单位为px
boolean / {maxHeight?: number; minHeight?: number}-false
text-align文本位置,stringleft / center / right-
readonly只读属性boolean-false
disabled禁用属性boolean-false
autofocus自动获取焦点boolean-false
cursor-spacing指定光标与键盘的距离。取textarea距离底部的距离和cursor-spacing指定的距离的最小值作为光标与键盘的距离number-0
cursor指定focus时的光标位置number--1
show-confirm-bar是否显示键盘上方带有”完成“按钮那一栏boolean-false
selection-start光标起始位置,自动聚集时有效,需与selection-end搭配使用number--1
selection-end光标结束位置,自动聚集时有效,需与selection-start搭配使用number--1
adjust-position键盘弹起时,是否自动上推页面boolean-false
hold-keyboardfocus时,点击页面的时候不收起键盘boolean-false
disable-default-padding是否去掉 iOS 下的默认内边距boolean-false
confirm-type设置键盘右下角按钮的文字stringsend / search / next / go / done / returnreturn
confirm-hold点击键盘右下角按钮时是否保持键盘不收起boolean-false
adjust-keyboard-to键盘对齐位置stringcursor / bottomcursor

Events

事件名说明回调参数
change输入框值改变时触发value
focus聚焦时触发event
blur失焦时触发value,event
confirm点击完成按钮时触发event
input键盘输入时触发value,event

主题定制

样式变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 组件

名称默认值
--nut-textarea-fontvar(--nut-font-size-2)
--nut-textarea-limit-colorvar(--nut-text-color)
--nut-textarea-text-colorvar(--nut-title-color)
--nut-textarea-disabled-colorvar(--nut-disable-color)

MIT Licensed