问题:uniapp使用uview2.0 u-textarea设置了maxlength,但在手机上粘贴字数可以超过了限制统计字数。 解决:在onReady生命周期函数中设置
- onReady() 页面初次渲染完成时触发。一个页面只会调用一次,代表页面已经准备妥当,可以和视图层进行交互。
<template>
<u-textarea
ref="textarea"
autoHeight
height="70px"
:count="true"
border="bottom"
maxlength="20"
v-model="name"
placeholder="请输入名称"
></u-textarea>
</template>
<script>
onReady(){
this.$refs.textarea.serFormatter(value=>{
if(value.length>=20){
return value.substr(0,20)
}else{
return value
}
})
}
</script>