【发布时间】: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