欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

解決uni-app微信小程序input輸入框在底部時(shí),鍵盤彈起頁面整體上移問題

 更新時(shí)間:2022年08月19日 11:36:54   作者:葉子_o  
問題是這樣的input?獲取焦點(diǎn)時(shí)會(huì)自動(dòng)調(diào)起手機(jī)鍵盤,設(shè)置?:adjust-position="true",會(huì)導(dǎo)致鍵盤彈起時(shí)頁面整體上移,這篇文章主要介紹了解決uni-app微信小程序input輸入框在底部時(shí),鍵盤彈起頁面整體上移問題,,需要的朋友可以參考下

問題描述:

最近的做了個(gè)客服聊天的功能,遇到一個(gè)問題如下:
在手機(jī)上點(diǎn)擊聊天頁底部的input框后,鍵盤彈起同時(shí)頁面會(huì)整體上移,標(biāo)題欄被頂上去了。如下圖:

問題分析:

input 獲取焦點(diǎn)時(shí)會(huì)自動(dòng)調(diào)起手機(jī)鍵盤,設(shè)置 :adjust-position="true",會(huì)導(dǎo)致鍵盤彈起時(shí)頁面整體上移

解決思路:

  • 設(shè)置使鍵盤彈起使頁面不上移
  • 設(shè)置輸入框所在盒子為絕對(duì)定位
  • 鍵盤彈起時(shí)獲取鍵盤高度
  • 設(shè)置輸入框所在盒子的bottom的鍵盤高度

注意:我這里是將消息輸入部分封裝成了組件,引入到它所在的 view 里的,所以需要將鍵盤高度子傳父?jìng)髦到o它所在的盒子,如果是在同一個(gè)文件中的話直接將獲取到的鍵盤高度賦值給 bottom 就可以。

1. input

<input
	class="TUI-message-input-area"
	:adjust-position="false"  // 修改為 false,使鍵盤彈起頁面不上移
	cursor-spacing="20"
	v-model="inputText"
	@input="onInputValueChange"
	maxlength="140"
	type="text"
	placeholder-class="input-placeholder"
	placeholder="說點(diǎn)什么呢~"
	@focus="inputBindFocus" // 添加獲取焦點(diǎn)鍵盤彈起事件
	@blur="inputBindBlur" // 添加失去焦點(diǎn)鍵盤隱藏事件
/>

重點(diǎn)在這里!?。∥也瓤颖徽勰ズ芫玫囊粋€(gè)地方?。?!一定要用 px!??!

methods: {
	inputBindFocus(e) {
		// 獲取手機(jī)鍵盤的高度,賦值給input 所在盒子的 bottom 值
		// 注意!!! 這里的 px 至關(guān)重要!!! 我搜到的很多解決方案都沒有說這里要添加 px
		this.$emit('changeBottomVal',  e.detail.height + 'px')
	},
   
	inputBindBlur() {
		// input 失去焦點(diǎn),鍵盤隱藏,設(shè)置 input 所在盒子的 bottom 值為0
		this.$emit('changeBottomVal', 0)
	}
}

2. input 所在的盒子:

<view v-if="showChat" class="message-input" :style="{ bottom: bottomVal }">
	<TUI-message-input id="message-input" ref="messageInput" :conversation="conversation" @sendMessage="sendMessage" @changeBottomVal="changeBottomVal"/>
</view>
data() {
	return {
		bottomVal: ''
	}
}
methods: {
	changeBottomVal(val) {
		this.bottomVal = val
	}
}
.message-input {
	flex-shrink: 0;
	width: 100%;
	position: absolute; // input 所在盒子設(shè)置絕對(duì)定位
	left: 0;
	bottom: 0; // 默認(rèn) 0
	z-index: 199;
}

總結(jié):

由于獲取的系統(tǒng)的尺寸單位都是 px ,給 bottom 設(shè)置的值單位也一定要是 px ! 不能因?yàn)槭鞘謾C(jī)端就用 rpx,2倍的 rpx 也不可以,因?yàn)椴⒉皇敲總€(gè)手機(jī)分辨率都是我們?cè)O(shè)計(jì)圖上375的2倍,一定要用 px ?。。。?/p>

到此這篇關(guān)于解決uni-app微信小程序input輸入框在底部時(shí),鍵盤彈起頁面整體上移問題的文章就介紹到這了,更多相關(guān)uni-app微信小程序input輸入框內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論