2016-10-06 29 views
1

我試圖測試裏面的React運行createjs,但我無法找到運行此。請有人指出我做錯了請。由於在React中運行Createjs?

import React from "react"; 
import ReactDOM from "react-dom"; 

export default class CanvasChart extends React.Component { 
    constructor() { 
    super(); 
    } 

    componentDidMount(){ 
    var canvas = ReactDOM.findDOMNode(this.refs.canvas); 
    this.stage = new createjs.Stage(canvas); 
    var circle = new createjs.Shape(); 
    circle.graphics.beginFill("DeepSkyBlue").drawCircle(0, 0, 50); 
    circle.x = 100; 
    circle.y = 100; 
    this.stage.addChild(circle); 
    this.stage.update(); 
    } 

    render() { 
    return (
    <canvas ref="canvas" width="500" height="300"></canvas> 
    ); 
    } 
} 

回答

1

你的代碼實際上works,也許你正在做一些錯誤的配置。

class CanvasChart extends React.Component { 
    constructor() { 
    super(); 
    } 

    componentDidMount(){ 
    var canvas = ReactDOM.findDOMNode(this.refs.canvas); 
    this.stage = new createjs.Stage(canvas); 
    var circle = new createjs.Shape(); 
    circle.graphics.beginFill("DeepSkyBlue").drawCircle(0, 0, 50); 
    circle.x = 100; 
    circle.y = 100; 
    this.stage.addChild(circle); 
    this.stage.update(); 
    } 

    render() { 
    return (
    <canvas ref="canvas" width="500" height="300"></canvas> 
    ); 
    } 
} 


ReactDOM.render(<CanvasChart />, 
    document.getElementById('root') 
); 
+0

謝謝。我在渲染畫布之前運行了代碼,這就是爲什麼它不顯示任何錯誤而不顯示。謝謝。 –

+0

你是對的,我沒注意到。 –

相關問題