Uncaught TypeError: Cannot create property 'style' on string 'wtd_background_image'

Uncaught TypeError: Cannot create property 'style' on string 'wtd_background_image'

我的 wordpress 插件适用于 fabric.js 1.2.0,当我将其更改为适用于 fabric.js 1.7.9 时,它会在除插件页面以外的所有页面上抛出错误:

Cannot create property 'style' on string 'wtd_background_image'

在以下行中:

canvasObj= new fabric.Canvas('wtd_background_image');

您需要在所有页面上创建 ID 为 wtd_background_image 的 HTML Canvas 元素。

let canvas = new Canvas('wtd_background_image');
let canvasObj = new fabric.Canvas('wtd_background_image');

function Canvas(id) {
    this.canvas = document.createElement('canvas');
    this.canvas.id = id;
    document.body.appendChild(this.canvas);
    return this.canvas;
}

// for demonstration
let circle = new fabric.Circle({radius: 20, fill: '#07C', left: 30, top: 30});
canvasObj.add(circle);
<script src="http://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.7.9/fabric.min.js"></script>