问题
2月初,Chrome(版本号109.0.5414.120)在一次降级中删除绑定点击等等局部事件中的Event.path数组参数,(Edge和其余国产chromium内核浏览器是没有变动的),官网降级记录日志记录。\
最早从官网issue中可获知chromium内核团队早在21年就开始认为 Event.path 属于非标准 API,某些中央曾经开始删除event.path数组参数了。\
且event.path是Chrome内核独自反对的属性,不在MDN的规范中。所以兼容性还是存在毛病。
解决办法
办法1(不举荐):
var composed = Event.composedPath();
MDN中有一个composedPath办法,然而依据网上的某些网友反馈也有可能返回空数组(暂未找到起因)。
办法2(举荐):
本人仿照 composedPath() 办法原理,将以后所有的冒泡一层一层 parentNode 元素收集起来。在push到数组外面。
const composedPath = (e: Record<string, any>) => { // 以后有间接return let pathArr = e.path || (e.composedPath && e.composedPath()); // 优先判断 Event.composedPath() 办法是否为空数组 if ((pathArr || [).length) { return pathArr; } // 不存在则遍历target节点 let target = e.target e.path = [] while (target.parentNode !== null) { e.path.push(target) target = target.parentNode } // 最初在add进去 document 与 window对象 e.path.push(document, window) return e.path;};