【问题标题】:FabricJS: Cannot read property of 'e' of undefinedFabricJS:无法读取未定义的“e”的属性
【发布时间】:2021-05-08 18:54:08
【问题描述】:

得到以下错误,即使我知道错误的含义(对象未定义/为空,因此其属性 e 失败),我不确定为什么会出现此错误。很确定它与一些 FabricJS 对象有关,而不仅仅是普通的 Javascript。如果任何了解 FabricJS 的人都可以帮助我,那就太好了。

fabric.js:8466 Uncaught TypeError: Cannot read property 'e' of undefined
    at klass.onMouseDown (fabric.js:8466)
    at HubConnection.<anonymous> (chat.js:128)

我的代码:此函数是客户端代码,用于从服务器接收 mousedown 事件(从发送客户端获取该信息)。它在接收客户端上创建一个新的 PencilBrush 对象,并在发送客户端按下 mousedown 的相同位置启动它。基本上,我正在尝试实时显示发送客户端正在向接收客户端绘制的内容,这是有助于实现此目的的功能之一。

connection.on("ReceiveMouseDown", function (user, coordinate) {  //coordinate is a string

        console.log("inside receive mouse down: " + coordinate); //this returns {x: value, y: value}
        var coordinateObject = JSON.parse(coordinate);  
        console.log('coordinateObject is: ' + coordinateObject);  //this returns [object object]

        brush = new fabric.PencilBrush(canvas);
        brush.onMouseDown(coordinateObject);  //this is line 128, exception occurs here
        //brush.onMouseDown(coordinate);  I have also tried this way, but same exception happens
        canvas.renderAll();
    });

我的发现:我认为 PencilBrush.onMouseDown() 方法需要一个指针(如此处所示 http://fabricjs.com/docs/fabric.PencilBrush.html ),但文档不太擅长解释指针对象是什么。

【问题讨论】:

    标签: javascript fabricjs


    【解决方案1】:

    如果有人尝试使用最近的 Fabric js 并遇到同样的问题,请尝试关注。我使用的是 4.4.0 版

    var canvas = new fabric.Canvas(document.getElementById('canvasId'));//Primary canvas
    var canvas2 = new fabric.Canvas(document.getElementById('canvasId2'));//Drawing programmatically on second canvas
    
    
    //Getting points from first canvas
    const pointer = canvas.getPointer(e);
    
    
    
    //Drawing on second convas
    
    let options = {pointer,e:{}};
    canvas2.freeDrawingBrush.onMouseDown(initialPointer,options);
    

    【讨论】:

      【解决方案2】:

      我认为您使用的是 3.3 版。尝试使用 3.2 版而不是 3.3 版...源代码已稍作更改,需要额外的参数。

      【讨论】:

        猜你喜欢
        • 2020-05-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-30
        • 2019-10-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多