<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
相关推荐
九月十九4 分钟前
AviatorScript用法Jane - UTS 数据传输系统28 分钟前
VUE+ Element-plus , el-tree 修改默认左侧三角图标,并使没有子级的那一项不展示图标_.Switch1 小时前
Python Web开发:使用FastAPI构建视频流媒体平台菜鸟阿康学习编程1 小时前
JavaWeb 学习笔记 XML 和 Json 篇 | 020索然无味io2 小时前
XML外部实体注入--漏洞利用ThomasChan1232 小时前
Typescript 多个泛型参数详细解读爱学习的狮王3 小时前
ubuntu18.04安装nvm管理本机node和npm东锋1.33 小时前
使用 F12 查看 Network 及数据格式zhanggongzichu3 小时前
npm常用命令anyup_前端梦工厂3 小时前
从浏览器层面看前端性能:了解 Chrome 组件、多进程与多线程