Daily work issues
kingcwt2023-07-04前端javascript
<URL>
Violation Added non-passive event listener to a scroll-blocking <某些> 事件. Consider marking event handler as 'passive' to make the page more responsive. See [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);
};
};
}