uniapp获取键盘高度顶起底部输入框

2023-12-20 22:20

本文主要是介绍uniapp获取键盘高度顶起底部输入框,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

核心代码:

     uni.onKeyboardHeightChange((res) => {console.log(res.height);//转化为rpxthis.KeyHight = res.height;});

全部代码:

<template><view class="pagesone" :class="'bg-'+themeColor.name" style="padding-top: 100rpx;"><view class="searchdemo" :style="{bottom:KeyHight?KeyHight+'px':KeyHight}" style="display: flex;flex-direction: row;"><view class="input" :class="'input-'+themeColor.name"><view class="icon"><image class="icon-child" :src="'/static/search-'+themeColor.name+'.png'" /></view><input :adjust-position="false" :always-system="true" :value="searchContent" confirm-type="search" @confirm="search" @input="onInputSearch":class="'text-'+themeColor.name" class="input-text" placeholder="输入股票名称/缩写/代码"placeholder-class="placeholder-class" :focus="true"></input><view class="icon" v-show="this.searchContent!=''" @click="clearSearch()"><image class="icon-child" :src="'/static/delete.png'" /></view></view><text :class="'text-'+themeColor.name" @click="back"style="font-size: 32rpx;margin-top: 15rpx;margin-left: 20rpx;">取消</text></view><!-- <view style="margin-top: 30rpx; display: flex;flex-direction: row;justify-content: center;"><text :class="'text-'+themeColor.name" style="font-size: 28rpx;" v-show="tab == 1"@click="ChangeTab(1)">股票</text><text style="font-size: 28rpx;color: #6F6F6F;" v-show="tab != 1" @click="ChangeTab(1)">股票</text><text :class="'text-'+themeColor.name" style="font-size: 28rpx;margin-left: 130rpx;margin-right: 130rpx;"v-show="tab == 2" @click="ChangeTab(2)">概念</text><text style="font-size: 28rpx;color: #6F6F6F;margin-left: 130rpx;margin-right: 130rpx;" v-show="tab != 2"@click="ChangeTab(2)">概念</text><text :class="'text-'+themeColor.name" style="font-size: 28rpx;" v-show="tab == 3"@click="ChangeTab(3)">资讯</text><text style="font-size: 28rpx;color: #6F6F6F;" v-show="tab != 3" @click="ChangeTab(3)">资讯</text></view> --><view class="blist" :style="{bottom:KeyHight?KeyHight+40+'px':'80rpx'}" style="padding-top: 30rpx;" v-show="tab == 1"><block v-for="(item, index) in gpList.slice().reverse()" :key="index"><u-GPList :item="item"></u-GPList></block></view><view :class="'bg-'+themeColor.name" style='position: fixed;width:100%;height: 100%;z-index: 0;'></view></view></template><script>import uGPList from './search-main-gupiao-list.vue';export default {components: {uGPList,},data() {return {tab: 1,searchContent: "",gpList: [],KeyHight: 0,}},onLoad(option) {this.$statusColor.modification();uni.onKeyboardHeightChange((res) => {console.log(res.height);//转化为rpxthis.KeyHight = res.height;});},methods: {back() {uni.navigateBack({});},clearSearch() {this.searchContent = "";},ChangeTab(tab) {this.tab = tab;},/* 键盘上完成(回车)的事件 */search() {if (this.isBlank(this.searchContent)) {this.$toast("输入股票代码/首字母");return;}if (this.tab == 1) {this.search_index(this.searchContent);} else if (this.tab == 2) {} else if (this.tab == 3) {}},onInputSearch: function(e) {if (this.tab == 1) {this.searchContent = e.detail.value;if (this.searchContent != "") {this.search_index(this.searchContent);}} else if (this.tab == 2) {} else if (this.tab == 3) {}},search_index(word) {var _this = this;this.request({urlInfo: this.$REQUEST.SEARCH_INDEX,body: {word: word,showtype: 'app',},success(res) {console.log("search_index==", res)},fail: (res) => {console.log("search_index==", res)var newList = [];res.data.data.filter((item, i) => {var obj = {};var sList = item.split(" ")obj.code = sList[0];obj.name = sList[1];obj.sx = sList[2];obj.foxxcode = sList[3];newList[i] = obj;return item >= res.data.data.length})_this.gpList = newList;}})},},}
</script><style lang="scss">
.pagesone{width: 100%;height: 100%;
}
.searchdemo{//触底width: 100vw;position: absolute;bottom: 0;z-index: 99;//被键盘顶起
}
.blist{width: 100vw;position: absolute;bottom: 80rpx;z-index: 99;
}.icon {.icon-child {width: 40rpx;height: 40rpx;margin-top: 10rpx;}}.input {margin-left: 30rpx;width: 75%;height: 76rpx;display: flex;flex-direction: row;align-items: center;border-radius: 10rpx;padding-left: 20rpx;padding-right: 20rpx;}.input-text {margin-left: 20rpx;margin-right: 20rpx;width: 100%;font-size: 32rpx;}.placeholder-class {color: #6F6F6F;font-size: 32rpx;}
</style>

此方法适配ios和安卓

这篇关于uniapp获取键盘高度顶起底部输入框的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/517724

相关文章

C#如何在Excel文档中获取分页信息

《C#如何在Excel文档中获取分页信息》在日常工作中,我们经常需要处理大量的Excel数据,本文将深入探讨如何利用Spire.XLSfor.NET,高效准确地获取Excel文档中的分页信息,包括水平... 目录理解Excel中的分页机制借助 Spire.XLS for .NET 获取分页信息为什么选择 S

springboot3.x使用@NacosValue无法获取配置信息的解决过程

《springboot3.x使用@NacosValue无法获取配置信息的解决过程》在SpringBoot3.x中升级Nacos依赖后,使用@NacosValue无法动态获取配置,通过引入SpringC... 目录一、python问题描述二、解决方案总结一、问题描述springboot从2android.x

springboot的controller中如何获取applicatim.yml的配置值

《springboot的controller中如何获取applicatim.yml的配置值》本文介绍了在SpringBoot的Controller中获取application.yml配置值的四种方式,... 目录1. 使用@Value注解(最常用)application.yml 配置Controller 中

golang实现nacos获取配置和服务注册-支持集群详解

《golang实现nacos获取配置和服务注册-支持集群详解》文章介绍了如何在Go语言中使用Nacos获取配置和服务注册,支持集群初始化,客户端结构体中的IpAddresses可以配置多个地址,新客户... 目录golang nacos获取配置和服务注册-支持集群初始化客户端可选参数配置new一个客户端 支

Python版本信息获取方法详解与实战

《Python版本信息获取方法详解与实战》在Python开发中,获取Python版本号是调试、兼容性检查和版本控制的重要基础操作,本文详细介绍了如何使用sys和platform模块获取Python的主... 目录1. python版本号获取基础2. 使用sys模块获取版本信息2.1 sys模块概述2.1.1

Java发送SNMP至交换机获取交换机状态实现方式

《Java发送SNMP至交换机获取交换机状态实现方式》文章介绍使用SNMP4J库(2.7.0)通过RCF1213-MIB协议获取交换机单/多路状态,需开启SNMP支持,重点对比SNMPv1、v2c、v... 目录交换机协议SNMP库获取交换机单路状态获取交换机多路状态总结交换机协议这里使用的交换机协议为常

PyQt6 键盘事件处理的实现及实例代码

《PyQt6键盘事件处理的实现及实例代码》本文主要介绍了PyQt6键盘事件处理的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起... 目录一、键盘事件处理详解1、核心事件处理器2、事件对象 QKeyEvent3、修饰键处理(1)、修饰键类

MyBatis/MyBatis-Plus同事务循环调用存储过程获取主键重复问题分析及解决

《MyBatis/MyBatis-Plus同事务循环调用存储过程获取主键重复问题分析及解决》MyBatis默认开启一级缓存,同一事务中循环调用查询方法时会重复使用缓存数据,导致获取的序列主键值均为1,... 目录问题原因解决办法如果是存储过程总结问题myBATis有如下代码获取序列作为主键IdMappe

C#使用iText获取PDF的trailer数据的代码示例

《C#使用iText获取PDF的trailer数据的代码示例》开发程序debug的时候,看到了PDF有个trailer数据,挺有意思,于是考虑用代码把它读出来,那么就用到我们常用的iText框架了,所... 目录引言iText 核心概念C# 代码示例步骤 1: 确保已安装 iText步骤 2: C# 代码程

Spring Boot中获取IOC容器的多种方式

《SpringBoot中获取IOC容器的多种方式》本文主要介绍了SpringBoot中获取IOC容器的多种方式,包括直接注入、实现ApplicationContextAware接口、通过Spring... 目录1. 直接注入ApplicationContext2. 实现ApplicationContextA