Skip to content

Textarea 文本域

iPhone

此组件满足了可能出现的表单信息补充,编辑等实际逻辑的功能,内置了字数校验等。

平台差异说明

APPH5微信小程序支付宝小程序QQ小程序···
适配中

代码示例

部分功能示例,具体可参考示例程序以及文档API。

基础用法

html
<template>
    <fu-textarea v-model="value" placeholder="请输入内容"></fu-textarea>
</template>

<script setup>
    import { ref } from 'vue';

    // data数据
    let value = ref('');
</script>

设置字数统计

通过 count 属性开启字数统计功能。

html
<template>
    <fu-textarea v-model="value" placeholder="请输入内容" count></fu-textarea>
</template>

<script setup>
    import { ref } from 'vue';

    // data数据
    let value = ref('字数统计');
</script>

设置自动增高

通过 autoHeight 属性开启自动增高功能。

html
<template>
    <fu-textarea v-model="value" placeholder="请输入内容" autoHeight></fu-textarea>
</template>

<script setup>
    import { ref } from 'vue';

    // data数据
    let value = ref('');
</script>

设置禁用状态

通过 disabled 属性设置禁用状态, 您也可以动态设置是否禁用。

html
<template>
    <fu-textarea v-model="value" placeholder="文本域已被禁用" disabled></fu-textarea>
</template>

<script setup>
    import { ref } from 'vue';

    // data数据
    let value = ref('');
</script>

设置下划线模式

通过 border="bottom" 属性单独设置底部下划线

html
<template>
    <fu-textarea v-model="value" placeholder="请输入内容" border="bottom"></fu-textarea>
</template>

<script setup>
    import { ref } from 'vue';

    // data数据
    let value = ref('');
</script>

格式化处理

如果有需要,可以通过 formatter 属性编写自定义格式化规则。

html
<template>
    <fu-textarea ref="textareaRef" v-model="value" placeholder="请输入内容" :formatter="formatter"></fu-textarea>
</template>

<script setup>
    import { ref } from 'vue';
    import { onReady } from '@dcloudio/uni-app';

    // data数据
    const textareaRef = ref();
    let value = ref('');

    // 生命周期
    onReady(() => {
        // 如果需要兼容微信小程序,需要调用此方法
        textareaRef.value.setFormatter(formatter);
    });

    // 自定义格式化函数
    function formatter(value) {
        // 让输入框只能输入数值,过滤其他字符
        return value.replace(/[^\d]/g, '');
    };
</script>

API

Textarea Props

属性名说明类型默认值可选值
value输入框的内容String|Number--
placeholder输入框为空时占位符String|Number--
placeholderClass输入框为空时占位符的样式类String--
placeholderStyle输入框为空时占位符的样式String|Object--
height输入框高度String|Number70-
confirmType设置键盘右下角按钮的文字,仅微信小程序,App-vue和H5有效Stringdone-
disabled是否禁用输入框Booleanfalsetrue
count是否开启字数统计Booleanfalsetrue
focus是否聚焦输入框Booleanfalsetrue
autoHeight是否自动增高输入框Booleanfalsetrue
fixed如果textarea是在一个position:fixed的区域,需要显示指定属性fixed为trueBooleanfalsetrue
cursorSpacing指定光标与键盘的距离Number0-
cursor指定focus时的光标位置String|Number--
showConfirmBar是否显示键盘上方带有”完成“按钮那一栏Booleantruefalse
selectionStart光标起始位置,自动聚焦时有效,需与selection-end搭配使用Number-1-
selectionEnd光标结束位置,自动聚焦时有效,需与selection-start搭配使用Number-1-
adjustPosition键盘弹起时,是否自动上推页面Booleantruefalse
disableDefaultPadding是否去掉 iOS 下的默认内边距,只微信小程序有效Booleanfalsetrue
holdKeyboard点击键盘时是否保持键盘不收起, 只微信小程序有效Booleanfalsetrue
maxlength最大输入长度,设置为 -1 的时候不限制最大长度String|Number140-
border边框类型,surround-四周边框,bottom-底部边框Stringsurroundbottom
borderColor边框颜色String#dadbde-
size自定义文字大小String|Number14-
formatter用于处理或者过滤输入框内容的方法Functionnull-
customStyle定义需要用到的外部样式String|Object--

Textarea Methods

方法名说明
setFormatter为兼容微信小程序而暴露的内部方法,见上方说明

Textarea Events

事件名说明回调参数
focus输入框聚焦时触发() => void
blur输入框失去焦点时触发() => void
input输入内容时触发() => void
confirm点击完成按钮时触发() => void
linechange输入框行数变化时触发() => void
change输入框内容变化时触发() => void
keyboardheightchange键盘高度变化时触发() => void