无法将事件侦听器添加到对象。结构体

can`t add event listener to object. fabricjs

无法将事件侦听器添加到对象。也许有人解决了同样的问题?我收到错误 "Uncaught TypeError: canvas.on is not a function"。我也用jQuery,这会不会有问题?我的代码:

window.onload = function() {
       var canvas = new fabric.Element('canvas');
       var imgElement = document.getElementById('uploaded_img');
       var width = imgWidth = imgElement.width;
       var height = imgHeight = imgElement.height;

       if(width >= screen.width){
           width = (screen.width - 70);
       }

       canvas.setWidth(width);
       canvas.setHeight(height);

       var imgInstance = new fabric.Image(imgElement, {
         left: width/2,            
         top: height/2         
       });                     
       canvas.add(imgInstance);

       canvas.on('mouse:up',function () {
          alert('test');
       });
}

来自http://fabricjs.com/docs/fabric.Canvas.html

fabric. Canvas
fabric.Element
new Canvas() §
Deprecated:
Use fabric.Canvas instead.
Source:
fabric.js, line 9066

因此 Fabric.Element 已弃用。因此强烈建议不要使用它。

无论如何,我在文档中找不到任何关于这个已弃用 'Element' 方法的信息。

所以我认为您的问题的答案是使用推荐的 Canvas 构造函数。正如错误所说,我还假设元素上实际上不存在 on() 方法。