<template>
<van-cell-group>
<van-field v-model="inputText" :disabled="props.disable" autosize type="textarea"
:placeholder="t('app_plz_input_content')" @focus="openKeyboard" @blur="closeKeyboard" />
</van-cell-group>
<!-- 使用KeyboardMask 遮罩层组件 -->
<keyboard-mask :is-visible="isKeyboardVisible" @close="closeKeyboard" />
</template>
<script setup lang="ts">
import { onMounted, reactive, ref, watch } from 'vue'
import KeyboardMask from '@/components/KeyboardMask.vue' // 导入KeyboardMask组件
const isKeyboardVisible = ref(false)
// 添加遮罩层解决键盘弹出,点击空白处关闭键盘,触发页面点击事件
const originalHeight = document.documentElement.clientHeight || document.body.clientHeight
const handleResize = () => {
const resizeHeight = document.documentElement.clientHeight ||
document.body.clientHeight
if (resizeHeight < originalHeight) {
isKeyboardVisible.value = true
} else {
isKeyboardVisible.value = false
}
}
window.addEventListener('resize', handleResize)
const closeKeyboard = () => {
isKeyboardVisible.value = false
}
const openKeyboard = () => {
isKeyboardVisible.value = true
}
</script>
<style scoped lang="less">
</style>
##遮罩组件
<template>
<div class="keyboard-mask" v-show="isShowMask" @click="close"></div>
</template>
<script lang="ts" setup>
import { ref, watch } from 'vue'
const emits = defineEmits(['closeKeyBoardMask'])
const props = defineProps({
isVisible: Boolean
})
const isShowMask = ref<boolean>(false)
watch(
() => props.isVisible,
(newVal) => {
isShowMask.value = newVal
},
{ immediate: true }
)
const close = () => {
emits('closeKeyBoardMask')
}
</script>
<style>
/* 遮罩层样式 */
.keyboard-mask {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0);
/* 半透明黑色背景 */
z-index: 9999;
/* 确保遮罩层在最上层 */
}
</style>
【无标题】H5页面解决点击页面处关闭键盘,触发了页面的事件的问题
gaolei_eit2023-10-11 11:11
相关推荐
m0_7482382738 分钟前
项目升级Sass版本或升级Element Plus版本遇到的问题升讯威在线客服系统1 小时前
如何通过 Docker 在没有域名的情况下快速上线客服系统AsBefore麦小兜1 小时前
Vite vs WebpackLaughingZhu1 小时前
PH热榜 | 2025-02-23道不尽世间的沧桑3 小时前
第17篇:网络请求与Axios集成diemeng11194 小时前
AI前端开发技能变革时代:效率与创新的新范式bin91536 小时前
DeepSeek 助力 Vue 开发:打造丝滑的复制到剪贴板(Copy to Clipboard)晴空万里藏片云8 小时前
elment Table多级表头固定列后,合计行错位显示问题解决曦月合一8 小时前
html中iframe标签 隐藏滚动条奶球不是球8 小时前
el-button按钮的loading状态设置