我想使用FabricJS在现有的vaadin 12项目中绘制形状,但形状未显示。
test-design-1.html文件:
<div id="divCanvas">
<canvas id="c" height="800px" width="800px"> </canvas>
</div>
TestDesign1.java文件:
@Tag("test-design-1")
@JavaScript("src/views/js/jquery.min.js")
@JavaScript("src/views/js/fabric.js")
@JavaScript("src/views/js/1.js")
@HtmlImport("src/views/test-design-1.html")
1.js文件:
window.onload = function() {
let canvas = new fabric.Canvas('c');
alert('Objects count: ' + canvas._objects.length); //0
let rect = new fabric.Rect({
left: 100,
top: 100,
width:190,
height:240,
strokeWidth: 1,
stroke:'red',
fill:'green'
});
canvas.add(rect);
alert('Objects count: ' + canvas._objects.length); //1
canvas.renderAll();
}
运行后,弹出“对象数:1”,但矩形形状未显示。
我该如何解决?