这是一个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文件,但它只显示第一张图片而不是第二张图片。将错误称为“未捕获的TypeError:无法读取未定义的属性'set'”
我使用Fabric.js loadFromJSON()函数将json加载到canvas。 我也使用下面的语法,但它也没有帮助。
canvas.loadFromJSON(json,canvas.renderAll.bind(canvas));
答案 0 :(得分:1)
我得到了答案。 实际上,如果我们在画布内有图像,那么加载&在加载之前我们将它设置为活动元素,因此它会给出错误。 所以只需检查它是否已加载&如果没有加载,那就不要把它作为活动元素。
if(e) {
//make it as active element
}