BUG描述
参考这位博主描述(我自己未截图):https://blog.csdn.net/qq_35408366/article/details/128446528
原本长这样:
然后出现了显示的内容和获取到的内容不符,原本应该只有两百字,但是获取到的包括了键盘中的字,超过了200字
<view class="comment-input">
<textarea
v-model="evaluationInfo.advice"
class="input"
type="text"
fixed="true"
contenteditable="true"
auto-height="true"
:disabled="!isAlreadyEval ? '' : true"
placeholder-class="placeholder"
:placeholder="!evaluationInfo.advice && isAlreadyEval ? '无' : '叔叔阿姨您好,您对本次服务有什么意见建议吗?(限200字)'"
maxlength="200"
/>
</view>
一是:
监听键盘弹起和收下,控制输入的内容前两百字(自定义最大字数)
mounted() {
this.getKeyBoardHeight()
},
methods: {
getKeyBoardHeight() {
uni.onKeyboardHeightChange(res => {
console.log('高度', res.height)
if (res.height === 0) {
console.log('键盘收起')
} else {
console.log('键盘弹起')
}
})
}
}
二是:
@input(虽然找了半天才发现这个很好用,记录一下,显得我很蠢),后面就解决了,憨憨办法
<textarea
v-model="evaluationInfo.advice"
class="input"
type="text"
fixed="true"
contenteditable="true"
auto-height="true"
:disabled="!isAlreadyEval ? '' : true"
placeholder-class="placeholder"
:placeholder="!evaluationInfo.advice && isAlreadyEval ? '无' : '叔叔阿姨您好,您对本次服务有什么意见建议吗?(限200字)'"
maxlength="200"
@input="getAdvice"
/>
getAdvice(e) {
console.log('输入内容', e.detail.value)
this.evaluationInfo.advice = e.detail.value.substring(0, 200)
},