【uniapp】关于小程序输入框聚焦、失焦(输入法占位)的问题

news/2024/7/20 4:34:42 标签: uni-app, 小程序

聊天小程序,界面带有输入框,当输入框中聚焦后,底部自动谈起输入法。此时输入框也要随之出现在输入法上方。默认情况下,输入框此时会被输入法覆盖掉。

以下是亲自实践,解决这个问题的方法:

一、小程序大概布局

<template>
	<view style="height: 100%; display: flex; flex-direction: column;">
		
		<!-- 自定义导航栏 -->
		<head-nav :navRedirectPage="navRedirectPage"></head-nav>
		
		<!-- 小程序界面内容 -->
		<view class="container" :style="containerStyle">
			<!-- 聊天界面内容 -->
			<scroll-view ref='list' :scroll-top="scrollTop" class="chat-container" :scroll-y="true"></scroll-view>
			
			<!-- 底部输入框 -->
			<view class="bottom-bar"  :style="bottom_autosize_style">
				<view class="input-view">
						<uv-textarea selectable="true" :cursor-spacing="20" v-model="inputText" :inputBorder="false" customStyle="overflow: scroll;max-height: 75px;border-width: 0px !important;background-color: #F7F7FC;margin-left: 12px;padding: 7px;"
			:adjust-position="false" :show-confirm-bar='false' @blur="inputBindBlur" :maxlength="500" autoHeight placeholder="请输入内容" @focus="inputBindFocus"></uv-textarea>					
					<button class="send-button" @click="sendMessage"
						:disabled="!inputText.trim().length>0 || sendDisabled">
						<image class="send-message" src="/static/v2/aichat/fasong.png" />
					</button>
				</view>
			</view>
		</view>
	</view>
</template>

css样式表:

  • 默认样式为:
	// 聊天窗口
	.chat-container {
		flex-grow: 1; // 窗口大小为可变
		overflow-y: auto;
	}

	// 底部输入框
	.bottom-bar {
			position: relative;
			display: flex;
			align-items: center;
			padding: 6px 13px 6px 13px;  // 主要是padding-bottom变化
	}
  • 当焦点在输入框内时,需要调整内容:
// 聚焦方法
inputBindFocus(e){
	console.log('e.detail.height:', e.detail.height)
	 if (e.detail.height) {
		   this.bottom_autosize_style = "padding-bottom:" +  (e.detail.height + 6ssss) + "px;"
		   if (!this.showScrollToBottom) {
		   	this.scrollToBottom();
		   }
	  }
},
// 失焦方法
inputBindBlur(){
	// this.containerStyle = ' height:' + this.containerHeight + 'px;';
	this.bottom_autosize_style = ""
	if (!this.showScrollToBottom) {
		this.scrollToBottom();
	}
}

请注意 bottom_autosize_style 这个变量的变化,即可实现。


http://www.niftyadmin.cn/n/5003875.html

相关文章

DBeaver新建Elasticsearch连接报错Error downloading driver libraries解决方案

1.软件版本背景 DBeaver Ultimate 22.1.0 elasticsearch 7.10 可能因DBeaver的版本不同&#xff0c;导致页面略有差异&#xff0c;请自行脑补&#xff01; 2.新建数据库&#xff08;Elasticsearch&#xff09;连接 点击新建数据库连接按钮 选择Elasticsearch 填写相关配置…

题目:2648.生成斐波那契数列

​​题目来源&#xff1a; leetcode题目&#xff0c;网址&#xff1a;2648. 生成斐波那契数列 - 力扣&#xff08;LeetCode&#xff09; 解题思路&#xff1a; 动态规划。 解题代码&#xff1a; /*** return {Generator<number>}*/ var fibGenerator function*() {le…

vs+opencv+QT调试程序

2021-09-28vsopencvQT简单的图像处理工程_opencv 用qt还是vs_二两山栀子的博客-CSDN博客 【vsopencvQt搭建简单的图像处理界面】https://www.bilibili.com/video/BV16T411j7XQ?vd_source0aeb782d0b9c2e6b0e0cdea3e2121eba 调试过程一直出现这种问题&#xff0c;后来改DEBUG为…

02JVM_垃圾回收GC

二、垃圾回收GC 在堆里面存放着java的所有对象实例&#xff0c;当对象为“死去”&#xff0c;也就是不再使用的对象&#xff0c;就会进行垃圾回收GC 1.如何判断对象可以回收 1.1引用计数器 介绍 在对象中添加一个引用计数器&#xff0c;当一个对象被其他变量引用时这个对象…

`Executor` 接口

Executor 接口是 Java 并发编程中的一个基础接口,用于表示能够执行任务的对象。它是一个功能非常简单的接口,只定义了一个方法 void execute(Runnable command),用于执行传递给它的 Runnable 任务。 以下是 Executor 接口的简单定义: public interface Executor { void e…

使用iCloud和Shortcuts实现跨设备同步与自动化数据采集

在如今的数字时代&#xff0c;跨设备同步和自动化数据采集对于提高工作效率和便利性至关重要。苹果的iCloud和Shortcuts App为我们提供了强大的工具&#xff0c;可以实现跨设备同步和自动化数据采集的功能。本文将详细介绍如何利用iCloud和Shortcuts App实现这些功能&#xff0…

新品登场!雅特力发布AT32F402与AT32F405高速USB2.0 OTG MCU

因应高速USB市场需求&#xff0c;产品技术不断推陈出新&#xff0c;USB2.0发展带来的高速连接能力&#xff0c;优化消费者的产品使用体验&#xff0c;且由于支持即插即用和热插拔&#xff0c;提高设备易用性&#xff0c;USB接口在各项设备中成为主流通用接口。在USB2.0标准中&a…

Android Studio 汉化

一、汉化&#xff1a; 查看版本号&#xff0c;查看Android Studio版本&#xff0c;根据版本下载对应的汉化包。例如我的是223。 下载汉化包&#xff1a; 中文语言包下载地址 找到对应的版本 回到Android Studio 1、进入设置 2、从磁盘安装插件 3、选择下载好的包点击OK 4、…