当前位置: 首页 > news >正文

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

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

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

一、小程序大概布局

<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.lryc.cn/news/159486.html

相关文章:

  • MySQL的故事——创建高性能的索引
  • 渗透测试漏洞原理之---【组件安全】
  • uni-app集成mui-player
  • 力扣(LeetCode)算法_C++—— 两个数组的交集
  • 异步编程 - 12 异步、基于事件驱动的网络编程框架 Netty
  • STM32 Nucleo-144开发板开箱bring-up
  • 计算机毕业设计 基于SSM的问卷调查管理系统的设计与实现 Java实战项目 附源码+文档+视频讲解
  • 基于SpringBoot的无忌在线考试系统(源码+讲解+调试运行)做毕设课设均可
  • 无涯教程-JavaScript - EOMONTH函数
  • 【LeetCode-面试经典150题-day21】
  • 算法刷题记录-双指针/滑动窗口(LeetCode)
  • Python基础tuple元组定义与函数
  • 【linux命令讲解大全】088.深入理解 shell 脚本中的 trap 命令
  • bean的管理-bean的获取
  • 如何快速清理已经上传到Git仓库的.DS_Store文件
  • 美的的笔试
  • Android 1.2 开发环境搭建
  • vue 页面加水印
  • Android ImageView详解
  • ElasticSearch第二讲:ES详解 - ElasticSearch基础概念
  • Ajax模拟视频点赞功能
  • java解决 衣服尺码 Compare T-Shirt Sizes
  • 基于python+Django深度学习的音乐推荐方法研究系统设计与实现
  • 【枚举区间+线段树】CF Ehu 152 E
  • 宏定义天坑记录
  • Git的一些常用概念与操作方法分享
  • webpack实战:某网站JS逆向分析
  • 826. 安排工作以达到最大收益;2257. 统计网格图中没有被保卫的格子数;816. 模糊坐标
  • JAVA毕业设计097—基于Java+Springboot+Vue+uniapp的医院挂号小程序系统(源码+数据库)
  • 4.3.3.1 【MySQL】CHAR(M)列的存储格式