将事件标记为显式非被动

将事件标记为显式非被动

本文介绍了将事件标记为显式非被动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个警告有点让我紧张。我有一个活动,我有时需要打电话给 preventDefault()

This warning is kinda getting on my nerves to be honest. I have an event where I sometimes need to call preventDefault()

有没有办法标记事件显然是非被动并摆脱这个警告?我知道它不会妨碍执行流程,但这是一个烦恼。我所能找到的就是如何将其标记为被动,但它是一个桌面应用程序,它不需要被动标记进行滚动优化。

Is there a way to mark the event as explicitly NOT passive and to get rid of this warning? I know it doesn't hamper execution flow, but it's an annoyance. All I can find is how to mark it passive, but it's a desktop app, which doesn't need the passive marker for scroll optimization.

我不知道是什么chrome认为当他们将其实现为默认警告时,会使开发控制台变得混乱。我觉得它就像EULAS上的同意按钮,不读,只需单击确定,cookie警告,只需单击确定...
我不想修复它,我希望忽略它,很好。

I'm not sure what chrome thought when they implemented this as default warning to clutter up the dev console. I feel like it's something like the agree button now on EULAS, don't read, just click ok, cookie warning, just click ok...I don't wish to fix it, I wish to ignore it, consiously.

推荐答案

添加侦听器时指定passive:false:

Specify passive: false when you add the listener:

el.addEventListener('click',someFn,{passive:false} );

请参阅:

这篇关于将事件标记为显式非被动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 06:29