uniapp输入框fixed定位,导致页面顶起解决方案

解决方案在pages页面中使用禁止页面向上顶起,设置fixed的bottom等于0即可

复制代码
"app-plus": {
	 "softinputMode": "adjustResize",
}

但由于我首页页面设置禁止顶起 页面显示会错乱原因是在键盘弹起时会导致 iOS 的 viewport 收缩,进而触发页面重新计算滚动位置。

所以我ios用的textarea的@keyboardheightchange

复制代码
<view @touchstart.stop="" @touchmove.stop="" @touchend.stop=""
					:style="{ bottom:'0px',zIndex:shareShow?'10 !important':'' }" class="inputbox">
					<view :style="{ background: offsetBottom==0 ? '#fff' : '#f5f6f9' }" class="innerboxinput">
						<view class="textareabox">
							<textarea :style="{ background: '#f5f6f9' }" :showConfirmBar="false" @tap.stop="onFocus"
								:autoHeight="true" :adjustPosition="false" :maxlength="500" :focus="autoFocus"
								:hold-keyboard="true" @keyboardheightchange="onKeyBoardHeightChange" @blur="onBlur"
								@focus="onFocus" :height="inputHeight" v-model="commentText"
								:placeholder="placeholderText"></textarea>
						</view>
						<view v-show="offsetBottom != 0" class="send-btn" @tap.stop="sendComment"
							:class="{ 'send-active': commentText?.trim().length > 0 }">
							发送
						</view>
						<view v-if="offsetBottom == 0" class="bottom-bar">
							<view class="action-btn" @tap="toggleLike">
								<image v-if="isLiked" src="./imgs/liked.png"
									style="width: 24px; height: 24px;margin-right: 5px;" mode=""></image>
								<image v-else src="./imgs/like.png" style="width: 24px; height: 24px;margin-right: 5px;"
									mode="">
								</image>
								<text class="action-count">{{ details?.praiseNumber || 0 }}</text>
							</view>
							<view style="margin-left: 10px;" class="action-btn" @tap="toggleCollect">
								<image v-if="isCollected" src="./imgs/collected.png"
									style="width: 24px; height: 24px;margin-right: 5px;" mode="">
								</image>
								<image v-else src="./imgs/collect.png"
									style="width: 24px; height: 24px;margin-right: 5px;" mode="">
								</image>
								<text class="action-count">{{ details?.hiddenNumber || 0 }}</text>
							</view>
							<view style="margin-left: 10px;" class="action-btn" @tap="">
								<image src="/static/imgs/rf-appcomment.png"
									style="width: 24px; height: 24px;margin-right: 5px;" mode="">
								</image>
								<text class="action-count">{{ details?.commentNumber || 0 }}</text>
							</view>
						</view>
					</view>
				</view>

const onKeyBoardHeightChange = (e) => {
		offsetBottom.value = e.detail.height > 0 ? e.detail.height : 0;
	};

使用@keyboardheightchange又会导致部分手机 输入框距离键盘过远

就用手动去改变softinputMode的值 ios等于adjustPan安卓等于adjustResize

这个是vue3的方法

javascript 复制代码
import {
		getCurrentInstance,
	} from 'vue'
const {
		proxy
	} = getCurrentInstance()
const sys = uni.getSystemInfoSync();


const appWebview = proxy.$scope.$getAppWebview()
		console.log("appWebview",appWebview)
		 appWebview.setStyle({ softinputMode: sys.platform=='ios'?'adjustPan':"adjustResize" });

vue2参考https://ask.dcloud.net.cn/question/113955

相关推荐
এ慕ོ冬℘゜17 分钟前
前端实战:jQuery 多条件联合搜索(标题模糊查询 + 日历时间段筛选)
前端·javascript·jquery
武子康26 分钟前
Search Console Platform Properties 扩大 SEO 资产边界:从 Page Ranking 到 Topic Coverage(5 类误读边界 + 3 表数据层设计)
前端·人工智能·后端
一点一木1 小时前
从60首歌到1个网站:输入你的故事,还你一首歌
前端·github
IT_陈寒2 小时前
Vue这个特性差点让我加班到凌晨,谁懂啊
前端·人工智能·后端
kyriewen2 小时前
我让AI改一个bug——它偷偷动了5个我没让它碰的地方
前端·javascript·ai编程
遇乐的果园3 小时前
前端学习笔记-vue加载渲染优化
前端·笔记·学习
用户985033593284 小时前
OpenLayers 热力图从原理到 Vue 组件一键接入
前端
颜酱4 小时前
01 | 骨架搭建:FastAPI + Vue 跑通第一个 SSE 流式问答
前端·人工智能·后端
hoLzwEge4 小时前
解码 IDE 智能提示:jsconfig.json 辅助开发全攻略
前端·前端框架
leoZ2314 小时前
记忆系统与 Agent 定制完全指南(四):自定义 Agent 开发(一)
前端·chrome