将事件标记为显式非被动 [英] Mark event as explicitly NOT passive
问题描述
[违规]为滚动阻止'wheel'事件添加了非被动事件监听器。考虑将事件处理程序标记为被动以使页面更具响应性。
[Violation] Added non-passive event listener to a scroll-blocking 'wheel' event. Consider marking event handler as 'passive' to make the page more responsive.
这个警告有点让我紧张。我有一个活动,我有时需要打电话给 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} );
请参阅: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
这篇关于将事件标记为显式非被动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!