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

相关推荐
胡志辉2 小时前
本地 AI 编码助手从 0 配起来:先选模型,再接 Ollama、VS Code、Claude Code 和 Codex
前端·后端
孟陬2 小时前
从 Claude Code 187 种说“正在处理”的方式看一流公司的用户体验
前端·claude·bun
一楼的猫3 小时前
从工具链视角对比:番茄作家助手 vs 第三方写作辅助方案
java·服务器·开发语言·前端·学习·chatgpt·ai写作
掘金一周3 小时前
想换一辆电车,JYM有什么推荐 | 沸点周刊 5.21
前端·人工智能·后端
Nian.Baikal3 小时前
Cesium 3D Tiles 加载与优化实战
前端·cesium
KaMeidebaby4 小时前
卡梅德生物技术快报|噬菌体肽库展示技术构建 Mhp168‑Hsp70 定向随机肽库:流程、质控与数据结果
前端·数据库·其他·百度·新浪微博
lchcy4 小时前
前端实现单点登录(SSO登录)
前端
卷帘依旧4 小时前
SPA下的路由模式详解
前端
环信5 小时前
2026年开发者选择即时通讯厂商应注意的几点
前端