Fabric.js loadFromJSON() not working properly. It gives javascript error "Uncaught TypeError: Cannot read property 'set' of undefined" in fabric.js

Fabric.js loadFromJSON() not working properly. It gives javascript error "Uncaught TypeError: Cannot read property 'set' of undefined" in fabric.js

这是一个json

{"objects":[{"type":"image","originX":"center","originY":"center","left":379,"top":136,"width":2000,"height":2000,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":0.1,"scaleY":0.1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","src":"http://localhost/kraftkadev/uploaded/shop/sticker-1.png","filters":[],"crossOrigin":""},{"type":"image","originX":"center","originY":"center","left":269,"top":299,"width":2000,"height":2000,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":0.1,"scaleY":0.1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","src":"http://localhost/kraftkadev/uploaded/shop/sticker-1.png","filters":[],"crossOrigin":""}],"background":""} 

这是我的 JSON 文件,但它只显示第一张图片而不是第二张图片,并给出错误“Uncaught TypeError: 无法读取 属性 'set'未定义"

我使用 Fabric.js loadFromJSON() 函数将 json 加载到 canvas。 我也使用了下面的语法,但它也没有帮助。

canvas.loadFromJSON(json,canvas.renderAll.bind(canvas));

我得到了答案。 实际上,如果我们在 canvas 中有图像,那么加载需要时间&在加载之前我们将其设置为活动元素,因此它会出错。 因此,只需检查它是否已加载,如果未加载,则不要将其作为活动元素。

if(e) {
//make it as active element
}