聊天输入框采用textarea高度自适应及显示内容不换行解决

<view class="oper flex-row" @tap.prevent.stop="" :style="'bottom:'+keyHeight+'px;'">
			<!--语音切换-->
			<image v-if="isEdit" @tap="toggleEdit(false)" src="../../../static/img/voice-circle.png" class="icon">
			</image>
			<image v-else @tap="toggleEdit(true)" src="../../../static/img/keyboard.png" class="icon"></image>
			<!--输入框-->
			<textarea v-if="isEdit" @focus="inputFocus" :focus="isFocus" :cursor-spacing="8" :adjust-position="false"
				v-model="content" class="input" placeholder="请输入内容" maxlength="-1" auto-height></textarea>
			<view v-else @touchstart="startVoice" @touchend="endVoice" @touchmove.stop.prevent="voiceIng"
				@touchcancel="voiceCancel" class="input" style="text-align: center;font-weight: 700;">{{ voiceTis }}
			</view>
			<!--表情-->
			<image @tap="togglePicker(200, 'emoji')" src="../../../static/img/emoji.png" class="icon"></image>
			<!--发送-->
			<view @touchend.prevent="send" v-show="content" class="btn">发送</view>
			<!--附件-->
			<image @tap="togglePicker(86, 'file')" v-show="!content" src="../../../static/img/add.png" class="icon">
			</image>
		</view>

使用textarea输入多行文本时会自动向下扩展,这里给外层oper加上固定定位:style="'bottom:'+keyHeight+'px;'使其在原位置保持不变并向上扩展

// 监听输入聚焦获取高度
			inputFocus(e) {
				this.setScrollHeight(e.detail.height)
				this.keyHeight = e.detail.height
				this.initScrollBar()
				uni.onKeyboardHeightChange(res => {
					this.setScrollHeight(res.height)
					this.keyHeight = res.height
					this.initScrollBar()
				})
			},

提交的内容显示不换行解决方法

.pre-text {
		white-space: pre-wrap;
	}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值