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

相关文章

一文详解如何使用Java获取PDF页面信息

《一文详解如何使用Java获取PDF页面信息》了解PDF页面属性是我们在处理文档、内容提取、打印设置或页面重组等任务时不可或缺的一环,下面我们就来看看如何使用Java语言获取这些信息吧... 目录引言一、安装和引入PDF处理库引入依赖二、获取 PDF 页数三、获取页面尺寸(宽高)四、获取页面旋转角度五、判断

Python使用OpenCV实现获取视频时长的小工具

《Python使用OpenCV实现获取视频时长的小工具》在处理视频数据时,获取视频的时长是一项常见且基础的需求,本文将详细介绍如何使用Python和OpenCV获取视频时长,并对每一行代码进行深入解析... 目录一、代码实现二、代码解析1. 导入 OpenCV 库2. 定义获取视频时长的函数3. 打开视频文

MySQL 获取字符串长度及注意事项

《MySQL获取字符串长度及注意事项》本文通过实例代码给大家介绍MySQL获取字符串长度及注意事项,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录mysql 获取字符串长度详解 核心长度函数对比⚠️ 六大关键注意事项1. 字符编码决定字节长度2

python3如何找到字典的下标index、获取list中指定元素的位置索引

《python3如何找到字典的下标index、获取list中指定元素的位置索引》:本文主要介绍python3如何找到字典的下标index、获取list中指定元素的位置索引问题,具有很好的参考价值,... 目录enumerate()找到字典的下标 index获取list中指定元素的位置索引总结enumerat

SpringMVC高效获取JavaBean对象指南

《SpringMVC高效获取JavaBean对象指南》SpringMVC通过数据绑定自动将请求参数映射到JavaBean,支持表单、URL及JSON数据,需用@ModelAttribute、@Requ... 目录Spring MVC 获取 JavaBean 对象指南核心机制:数据绑定实现步骤1. 定义 Ja

C++中RAII资源获取即初始化

《C++中RAII资源获取即初始化》RAII通过构造/析构自动管理资源生命周期,确保安全释放,本文就来介绍一下C++中的RAII技术及其应用,具有一定的参考价值,感兴趣的可以了解一下... 目录一、核心原理与机制二、标准库中的RAII实现三、自定义RAII类设计原则四、常见应用场景1. 内存管理2. 文件操

SpringBoot服务获取Pod当前IP的两种方案

《SpringBoot服务获取Pod当前IP的两种方案》在Kubernetes集群中,SpringBoot服务获取Pod当前IP的方案主要有两种,通过环境变量注入或通过Java代码动态获取网络接口IP... 目录方案一:通过 Kubernetes Downward API 注入环境变量原理步骤方案二:通过

使用Python实现获取屏幕像素颜色值

《使用Python实现获取屏幕像素颜色值》这篇文章主要为大家详细介绍了如何使用Python实现获取屏幕像素颜色值,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 一、一个小工具,按住F10键,颜色值会跟着显示。完整代码import tkinter as tkimport pyau

python获取cmd环境变量值的实现代码

《python获取cmd环境变量值的实现代码》:本文主要介绍在Python中获取命令行(cmd)环境变量的值,可以使用标准库中的os模块,需要的朋友可以参考下... 前言全局说明在执行py过程中,总要使用到系统环境变量一、说明1.1 环境:Windows 11 家庭版 24H2 26100.4061

Python使用pynput模拟实现键盘自动输入工具

《Python使用pynput模拟实现键盘自动输入工具》在日常办公和软件开发中,我们经常需要处理大量重复的文本输入工作,所以本文就来和大家介绍一款使用Python的PyQt5库结合pynput键盘控制... 目录概述:当自动化遇上可视化功能全景图核心功能矩阵技术栈深度效果展示使用教程四步操作指南核心代码解析