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

相关推荐
前端Hardy5 分钟前
GitHub 爆火!Three.js + React + ECharts 打造最强数据大屏
前端·javascript
如果超人不会飞5 分钟前
TinyRobot AI 对话组件库全组件使用指南
前端·vue.js
lichenyang4537 分钟前
ArkTS 资源与暗色模式:为什么我手机切暗色,App 内容区却不变
前端
老王以为25 分钟前
Claude Code 的产品哲学:当价值观成为架构
前端·claude·vibecoding
程序员黑豆29 分钟前
AI全栈开发 - Java:变量
java·前端·ai编程
tedcloud12332 分钟前
HyperFrames部署教程:用HTML生成MP4视频
前端·数据库·人工智能·html·音视频
江米小枣tonylua39 分钟前
真多线程!Bun作者要给JS大手术
前端
YIAN1 小时前
# 从入门到封装:一文搞懂 Fetch API 所有用法(新手友好)
前端·javascript
Slice_cy1 小时前
基于node实现服务端内核引擎
前端·后端
往事随风灬1 小时前
我被 Volta 的“智能”坑了一下午:pnpm 为何无视项目 Node 版本?
前端·vue.js