uni-app input组件的@click事件在部分新手机(小米14、OPPO 一加 pro等)的运行环境中不能触发
uni-app input组件的@click事件在部分新手机(小米14、OPPO 一加 pro等)的运行环境中不能触发
开发环境 | 版本号 | 项目创建方式 |
---|---|---|
Windows | 10 22H2 | HBuilderX |
产品分类:uniapp/App
PC开发环境操作系统:Windows
HBuilderX类型:正式
HBuilderX版本号:3.98
手机系统:Android
手机系统版本号:Android 14
手机厂商:小米
手机机型:小米14pro
页面类型:vue
vue版本:vue2
打包方式:云端
示例代码:
<input
style="text-align: right"
type="text"
placeholder="请输入内容"
[@click](/user/click)="openDialog()"
disabled="true"
class="inputText"
/>
操作步骤:
<input
style="text-align: right"
type="text"
placeholder="请输入内容"
[@click](/user/click)="openDialog()"
disabled="true"
class="inputText"
/>
预期结果:
- 点击input,触发openDialog方法
实际结果:
- 点击input,无法触发openDialog方法
bug描述:
<input
style="text-align: right"
type="text"
placeholder="请输入内容"
[@click](/user/click)="openDialog()"
disabled="true"
class="inputText"
/>
部分新手机无法触发click、tap事件,导致无法执行点击方法。
你好,问一下您出现问题的机型,点击输入框,是否能调用手机键盘?
我的也是这样的,input加disabled就无法触发click和tap
// 兼容Chrome内核116及以上版本中配置disabled的input组件无法触发并冒泡click事件 .uni-input-input:disabled { pointer-events: none; }
回复 5***@qq.com: 这个写在哪
回复 2***@qq.com: 我是把楼上的样式,写到app.vue里边,就可以了
在 uni-app
中使用 input
组件的 @click
事件时,可能会在某些新手机(如小米14、OPPO 一加 Pro 等)上无法触发。这通常是由于这些设备的系统或浏览器内核对事件处理机制的不同导致的。以下是一些可能的解决方案:
1. 使用 @focus
事件替代 @click
@click
事件在某些设备上可能无法正常触发,但 @focus
事件通常可以正常工作。你可以尝试将 @click
替换为 @focus
:
<input @focus="handleInputClick" />
2. 使用 @tap
事件
在 uni-app
中,@tap
事件是专门为移动端设计的,通常比 @click
更可靠。你可以尝试使用 @tap
事件:
<input @tap="handleInputClick" />
3. 使用 @touchstart
事件
@touchstart
事件是触摸事件的开始,通常可以在移动设备上正常工作:
<input @touchstart="handleInputClick" />
4. 检查 CSS 样式
有时,CSS 样式可能会影响事件的触发。确保 input
元素没有覆盖其他元素,或者没有被其他元素覆盖。你可以尝试调整 z-index
或 pointer-events
属性:
input {
z-index: 1;
pointer-events: auto;
}
5. 使用 cover-view
或 cover-image
如果你在 input
组件上使用了 cover-view
或 cover-image
,这些组件可能会阻止事件的触发。你可以尝试移除这些组件,或者调整它们的层级。
6. 更新 uni-app
版本
确保你使用的是最新版本的 uni-app
,因为新版本可能已经修复了与某些设备兼容性相关的问题。
7. 使用原生事件
如果以上方法都无法解决问题,你可以尝试使用原生事件来处理点击事件。例如,在 mounted
生命周期钩子中手动添加事件监听器:
mounted() {
const inputElement = this.$refs.inputElement;
inputElement.addEventListener('click', this.handleInputClick);
},
methods: {
handleInputClick() {
// 处理点击事件
}
}
8. 使用 uni-app
的 $emit
方法
你可以在 input
组件中使用 $emit
方法来触发自定义事件,然后在父组件中监听该事件:
<!-- 子组件 -->
<input @click="$emit('input-click')" />
<!-- 父组件 -->
<child-component @input-click="handleInputClick" />
9. 检查设备兼容性
如果问题仅在某些特定设备上出现,建议检查这些设备的系统版本和浏览器内核版本,看看是否有已知的兼容性问题。你可以尝试在这些设备上使用不同的浏览器进行测试,以确定是否是浏览器内核的问题。
10. 使用 uni-app
的 onShow
生命周期
如果 input
组件在页面加载时无法触发点击事件,你可以尝试在 onShow
生命周期钩子中手动触发事件:
onShow() {
this.handleInputClick();
}