1***@qq.com
1***@qq.com
  • 发布:2022-11-17 11:31
  • 更新:2022-11-17 11:31
  • 阅读:214

【报Bug】3.6.4以上版本 renderjs 使用document.addEventListener监听如键盘按下事件等,App端需触屏后才能监听到!3.5.3版本正常

分类:HBuilderX

产品分类: HbuilderX

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: 企业版 1909

HBuilderX版本号: 3.6.4

示例代码:

<template>
<view></view>
</template>

<script>
export default {
methods: {
onEvent(event) {
console.log(event)
// this.$emit(event.type, event)
},
},
}
</script>

<script module="keyboard" lang="renderjs">
export default {
mounted () {
const onKey = (event) => {
const keys1 = ['type', 'timeStamp']
const keys2 = ['altKey', 'code', 'ctrlKey', 'isComposing', 'key', 'location', 'metaKey', 'repeat', 'shiftKey']
const keys3 = ['char', 'charCode', 'keyCode', 'keyIdentifier', 'keyLocation', 'which']
const data = {}
keys1.concat(keys2, keys3).forEach(key => data[key] = event[key])
this.$ownerInstance.callMethod('onEvent', data)
}
const names = ['keydown', 'keyup']
names.forEach(name => {
document.addEventListener(name, onKey, false)
})
this.$on('hook:beforeDestroy', () => {
names.forEach(name => {
document.removeEventListener(name, onKey, false)
})
})
}
}
</script>

<style>
</style>

操作步骤:

复制代码示例,运行到模拟器

预期结果:

App端无需触屏直接监听到

实际结果:

App端需触屏后才能监听到

bug描述:

3.6.4以上版本 renderjs 使用document.addEventListener监听如键盘按下事件等,App端需触屏后才能监听到!3.5.3版本正常

2022-11-17 11:31 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复