textarea设置 maxlength为100,输入到第101个字时不显示,但成功输入,导致提交的数据出现长度限制的错误,代码片段如下:
<textarea v-show="textareaVisibale" @input="textareaInput($event,100,'memberDesc')" v-model="addForm.memberDesc" :show-confirm-bar="showConfirm" auto-height="true" maxlength="100" :adjust-position="inputUp" @focus="inputFocus" @blur="inputBlur"/>
textareaInput(event,maxlength,propertyName){
if(event.detail.cursor==maxlength){
uni.showToast({
title:'最多只能输入'+maxlength+'个字!',
icon:'none',
duration:2000
})
}else if(event.detail.cursor>maxlength){
uni.showToast({
title:'最多只能输入'+maxlength+'个字!',
icon:'none',
duration:2000
})
console.log('event.detail.cursor:',event.detail.cursor);
console.log('event.detail.value:',event.detail.value);
console.log('this.addForm[propertyName]:',this.addForm[propertyName]);
// this.addForm[propertyName]=this.addForm[propertyName].substring(0,maxlength)
// this.$set(event.detail,'value',event.detail.value.substring(0,maxlength))
}
},
测试结果如图: