无法在 canvas.loadFromJSON 上设置统一笔画宽度?

Not able to set Uniform stroke width on canvas.loadFromJSON?

所以我指定了矩形:

addRect() {
    let square = new fabric.Rect({
      width: 20,
      height: 30,
      stroke:"yellow",
      strokeWidth:10,
      left: 50,
      top: 50,
      strokeUniform:true,
      fill:"rgba(0,0,0,0.2)",
      flipX:true
    });
    this.canvas.add(square);
  }

在 canvas 我得到这样的东西:

我暂时保存canvas数据:

saveData() {
    let jsonData = JSON.stringify(this.canvas);
    localStorage.setItem('data', jsonData);
    this.dataPreview.nativeElement.value = jsonData;
  }

然后我将此数据加载回 canvas:

loadData() {
    let jsonData = localStorage.getItem('data');
    this.canvas.loadFromJSON(
      jsonData,
      () => {
        this.canvas.requestRenderAll();
        this.dataPreview.nativeElement.value = jsonData;
      },
      this.onDataLoadFailed
    );
  }

我在 canvas 上得到了这样的信息:

我该如何解决这个问题?我认为问题可能是因为 JSON 数据对 strokeUniform.

没有任何价值

strokeUniform 属性 已被 toObject 评论。

解决方法是将 属性 作为 toJSON method

的参数
console.log(JSON.stringify(canvas.toJSON("strokeUniform")));