简体   繁体   English

为什么我无法在我的 React 应用程序中访问 Konva Canvas 属性?

[英]Why can't I access Konva Canvas properties in my React app?

I am using the FabricJS library with ReactJS.我正在使用带有 ReactJS 的 FabricJS 库。 Here I want to create and use Konva.Canvas constructor methods.这里我想创建和使用 Konva.Canvas 构造函数方法。 But, I have a problem while accessing the Konva Canvas properties.但是,我在访问 Konva Canvas 属性时遇到了问题。

if I use canvas.add method I get ERROR canvas.add is not a function如果我使用 canvas.add 方法我得到 ERROR canvas.add is not a function

const Konva = window.Konva;
class Canvas extends Component {
    state ={
        canvas: null,
        width: null,
        height: null,
        layer: null,
    }
    componentDidMount() {
        const canvas = new Konva.Canvas({ 
            container: this.c,
            height:this.props.height,
            width:this.props.width
        });
        console.log(canvas);
        const layer = new Konva.Layer();
        this.setState({canvas,layer});
        // canvas.add(layer);
        layer.draw();
    }

Replaced更换

 const canvas = new Konva.Canvas({ 
        container: this.c,
        height:this.props.height,
        width:this.props.width
    });

with

 const canvas = new Konva.Stage({ 
        container: this.c,
        height:this.props.height,
        width:this.props.width
    });

Stage supports add method. Stage 支持 add 方法。 More info on https://konvajs.org/api/Konva.Stage.html#main有关https 的更多信息://konvajs.org/api/Konva.Stage.html#main

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM