Firefox和Vue.js未定义event.path

JavaScript

阿飞古一A

2020-03-11

首先,我使用Vue.js和Node.js

我的Firefox有问题。

我使用event.path[n].idFirefox时遇到错误

event.path未定义

但是它在其他浏览器中也可以正常工作。

你知道为什么吗

第797篇《Firefox和Vue.js未定义event.path》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

1个回答
番长千羽 2020.03.11

使用composePath()并为IE使用polyfill:https ://gist.github.com/rockinghelvetica/00b9f7b5c97a16d3de75ba99192ff05c

包括以上文件或粘贴代码:

// Event.composedPath
(function(e, d, w) {
  if(!e.composedPath) {
    e.composedPath = function() {
      if (this.path) {
        return this.path;
      } 
    var target = this.target;

    this.path = [];
    while (target.parentNode !== null) {
      this.path.push(target);
      target = target.parentNode;
    }
    this.path.push(d, w);
    return this.path;
    }
  }
})(Event.prototype, document, window);

然后使用:

var path = event.path || (event.composedPath && event.composedPath());

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android