【无标题】uni-app中当input框获取焦点时键盘弹起时,input框自动上推

在微信小程序移动端使用时,在一个uni-popup弹窗中,当input框获取焦点的时候@focus事件出发时,在键盘弹起时,怎么自动上推页面。

  1. 直接在input组件上配置adjust-position属性
<input :adjust-position="true"  v-model="name"  placeholder="请输入昵称" />
  1. 当配置完adjust-position属性后,自动上推页面的距离并不理想时,可采用计算键盘高度来增加popup弹出层里面包含块的高度
<template>
 <view>
<buttom @click="open">打开弹窗</buttom>
		<uni-popup ref="popup" type="bottom" :safe-area="false">
			<view class="popup-box" :style="'height:'+height+'rpx;'">
				

				<input class="textarea-box" :adjust-position="true" @focus="handleInputFocus" v-model="name"
					@blur="handleInputBlur" placeholder-style="color:#888888" placeholder="请输入昵称" />
				<button class="btn" @click="revamNickName">确定</button>
			</view>
		</uni-popup>
	</view>
</template>
	<script>
	export default {
		data() {
			return {
				name: '',
				height: 744,
			}
		},
		mounted() {

		},
		methods: {
		open(){
		this.$refs.popup.open('bottom')
		},
			handleInputFocus() {
				if (uni.getSystemInfoSync().platform === 'android' || uni.getSystemInfoSync().platform === 'ios') {
				  // console.log('运行在手机上');
				  // 计算键盘高度
				  const keyboardHeight = uni.getSystemInfoSync().windowHeight * 0.6;
				  this.height += keyboardHeight
				  // 设置弹窗距离底部的位置,使页面上推
				}
				
			},
			revamNickName() {
				console.log('修改===', this.name)
				this.$refs.popup.close()
			},
			close() {
				this.$refs.popup.close()
				this.height = 744
			},
			handleInputBlur() {
				// 还原弹窗距离底部的位置
				this.height = 744
			},
			changePopup() {
				this.close()
			},
		}
	}
</script>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值