<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
相关推荐
王哈哈^_^1 小时前
【数据集】【YOLO】【目标检测】交通事故识别数据集 8939 张,YOLO道路事故目标检测实战训练教程!cs_dn_Jie1 小时前
钉钉 H5 微应用 手机端调试开心工作室_kaic2 小时前
ssm068海鲜自助餐厅系统+vue(论文+源码)_kaic有梦想的刺儿2 小时前
webWorker基本用法cy玩具3 小时前
点击评论详情,跳到评论页面,携带对象参数写法:清灵xmf3 小时前
TypeScript 类型进阶指南小白学大数据3 小时前
JavaScript重定向对网络爬虫的影响及处理qq_390161773 小时前
防抖函数--应用场景及示例334554324 小时前
element动态表头合并表格John.liu_Test4 小时前
js下载excel示例demo