Skip to content

Textarea

The text field component satisfies the actual logic functions such as form information supplementation and editing that may appear, and has built-in word count verification, etc.

platform compatibility

App(vue)App(nvue)H5小程序VUE2VUE3

basic use

vue
<template>
    <wu-textarea v-model="value1" placeholder="Please enter content"></wu-textarea>
</template>
<script>
	export default {
		data() {
			return {
				value1: '',
			}
		},
	}
</script>
<template>
    <wu-textarea v-model="value1" placeholder="Please enter content"></wu-textarea>
</template>
<script>
	export default {
		data() {
			return {
				value1: '',
			}
		},
	}
</script>

Count

Set the count attribute to achieve word count

vue
<template>
    <wu-textarea v-model="value2" placeholder="Please enter content" count></wu-textarea>
</template>
<script>
	export default {
		data() {
			return {
				value2: 'Statistics',
			}
		},
	}
</script>
<template>
    <wu-textarea v-model="value2" placeholder="Please enter content" count></wu-textarea>
</template>
<script>
	export default {
		data() {
			return {
				value2: 'Statistics',
			}
		},
	}
</script>

Auto Height

Set the autoHeight attribute to achieve automatic heightening

vue
<template>
    <wu-textarea v-model="value3" placeholder="Please enter content" autoHeight></wu-textarea>
</template>
<script>
	export default {
		data() {
			return {
				value3: '',
			}
		},
	}
</script>
<template>
    <wu-textarea v-model="value3" placeholder="Please enter content" autoHeight></wu-textarea>
</template>
<script>
	export default {
		data() {
			return {
				value3: '',
			}
		},
	}
</script>

Disabled state

Set the disabled property to disable, you can also dynamically set whether to disable

vue
<template>
    <wu-textarea v-model="value4" placeholder="Please enter content" disabled count></wu-textarea>
</template>
<script>
	export default {
		data() {
			return {
				value4: '',
			}
		},
	}
</script>
<template>
    <wu-textarea v-model="value4" placeholder="Please enter content" disabled count></wu-textarea>
</template>
<script>
	export default {
		data() {
			return {
				value4: '',
			}
		},
	}
</script>

underline mode

Set the border="bottom" attribute to set the bottom underline separately

vue
<template>
    <wu-textarea v-model="value5" placeholder="Please enter content" border="bottom"></wu-textarea>
</template>
<script>
	export default {
		data() {
			return {
				value5: '',
			}
		},
	}
</script>
<template>
    <wu-textarea v-model="value5" placeholder="Please enter content" border="bottom"></wu-textarea>
</template>
<script>
	export default {
		data() {
			return {
				value5: '',
			}
		},
	}
</script>

Formatting

If desired, custom formatting rules can be written via the formatter parameter.

vue
<template>
    <wu-textarea v-model="value" :formatter="formatter" ref="textarea"></wu-textarea>
</template>

<script>
    export default {
        data() {
            return {
                value: ''
            }
        },
		onReady() {
			// If you need to be compatible with WeChat applets, you need to use this method
			this.$refs.textarea.setFormatter(this.formatter)
		},
        methods: {
            formatter(value) {
				// Let the input box only enter values, and filter other characters
            	return value.replace(/[^0-9]/ig, "")
            }
        },
    }
</script>
<template>
    <wu-textarea v-model="value" :formatter="formatter" ref="textarea"></wu-textarea>
</template>

<script>
    export default {
        data() {
            return {
                value: ''
            }
        },
		onReady() {
			// If you need to be compatible with WeChat applets, you need to use this method
			this.$refs.textarea.setFormatter(this.formatter)
		},
        methods: {
            formatter(value) {
				// Let the input box only enter values, and filter other characters
            	return value.replace(/[^0-9]/ig, "")
            }
        },
    }
</script>

API

Textarea Props

property namedescriptiontypedefault valueoptional values ​​
value / modelValuecontent of input boxString--
placeholderplaceholder when the input box is emptyNumber / String--
heightinput box heightString / Number70-
confirmTypeSet the text of the button in the lower right corner of the keyboard, only valid for WeChat applets, App-vue and H5Stringdone-
disabledWhether to disableBooleanfalsetrue / false
countWhether to display the count of wordsBooleanfalsetrue / false
focusWhether to automatically get the focus, nvue does not support it, H5 depends on the implementation of the browserBooleanfalsetrue / false
autoHeightWhether to automatically increase the heightBooleanfalsetrue / false
ignoreCompositionEventWhether to ignore the processing of text composition system events within the component. When false, compositionstart, compositionend, compositionupdate events will be fired, and input event will be fired during text compositionBooleantruetrue / false
fixedIf the textarea is in a position:fixed area, it needs to display the specified attribute fixed as trueBooleanfalsetrue / false
cursorSpacingSpecifies the distance between the cursor and the keyboardNumber0-
cursorcursor position when focus is specifiedNumber / String0-
showConfirmBarWhether to show the bar with the "Done" button above the keyboard,Booleantruetrue / false
selectionStartCursor start position, valid when auto focus, need to be used together with selection-endNumber-1-
selectionEndThe end position of the cursor, valid during auto-focus, must be used with selection-startNumber-1-
adjustPositionWhether to automatically push up the page when the keyboard pops upBooleantruetrue / false
disableDefaultPaddingWhether to remove the default padding under iOS, only valid for WeChat appletsBooleanfalsetrue / false
holdKeyboardWhen in focus, the keyboard will not be put away when the page is clicked, only the WeChat applet is validBooleanfalsetrue / false
maxlengthThe maximum input length, when set to -1, there is no limit to the maximum lengthString / Number140-
borderborder type, surround-surround border, none-no border, bottom-bottom borderStringsurroundbottom
placeholderClassSpecifies the style class of the placeholder. Note that when scoped is written in the style of the page or component, you need to write /deep/ before the class nameStringtextarea-placeholder-
placeholderStyleSpecifies the style of the placeholder, in the form of a string/object, such as "color: red;"String / Objectcolor: #c0c4cc-
formatterInput filtering or formatting function (if compatible with WeChat applet, only through the setFormatter method)Functionnull-

Textarea Methods

method namedescription
setFormatterThe internal method exposed for compatibility with WeChat applets, see the description above

Textarea Event

Event NameDescriptionCallback Parameters
focusTriggered when the input box is focused, event.detail = { value, height }, height is the height of the keyboarde
blurTriggered when the input box loses focus, event.detail = {value, cursor}e
linechangeCalled when the line number of the input box changes, event.detail = {height: 0, heightRpx: 0, lineCount: 0}e
inputWhen the keyboard enters, the input event is triggerede.detail.value
confirmWhen the click is done, the confirm event is triggerede
keyboardheightchangeThis event is triggered when the keyboard height changese