Daily work issues

kingcwt2023-07-04前端javascript

Violation Added non-passive event listener to a scroll-blocking <某些> 事件. Consider marking event handler as 'passive' to make the page more responsive. See <URL>

[Violation] Added non-passive event listener to a scroll-blocking <某些> 事件. Consider marking event handler as 'passive' to make the page more responsive. See <URL>

解决办法:

  • 项目里安装
npm i default-passive-events
  • 在项目入口文件中引入
import 'default-passive-events'

最佳解决办法:

  • 在main入口文件执行该函数
/**
 * @desc 去除touch事件谷歌警告
 */
export const  polyfillTouch = () => {
  if (typeof EventTarget !== "undefined") {
    let func = EventTarget.prototype.addEventListener;
    (EventTarget as any).prototype.addEventListener = function (type: any, fn: any, capture: { passive?: any; }) {
      this.func = func;
      if (typeof capture !== "boolean") {
        // eslint-disable-next-line no-param-reassign
        (capture as any) = capture || {};
        capture.passive = false;
      }
      this.func(type, fn, capture);
    };
  };
}
Last Updated 10/16/2023, 7:06:22 AM
What do you think?
  • 0
  • 0
  • 0
  • 0
  • 0
  • 0
Comments
  • Latest
  • Oldest
  • Hottest
Powered by Waline v2.15.8