"Unable to preventDefault inside passive event listener invocation"是浏览器开发中的一个警告信息。这个警告通常出现在使用passive事件监听器时,当在事件处理函数中调用preventDefault()方法时会引发该警告,不会实际影响使用,就是控制台一直报红贼难看
解决方案(亲测有效):
1.新建公用文件:browserPatch.js(可以是在common目录或者untils目录,根据自己的项目定)
;(function () {
if (typeof EventTarget !== 'undefined') {
const func = EventTarget.prototype.addEventListener;
EventTarget.prototype.addEventListener = function (type, fn, capture) {
this.func = func;
if (typeof capture !== 'boolean') {
capture = capture || {};
capture.passive = false;
}
this.func(type, fn, capture);
};
}
})();
2.然后再在main.js文件中,引入该文件:
import '@/utils/browserPatch'
ts转行书写格式同理