react中应用canvas,存在多个canvas子组件,图像如何渲染?

render() {    
    return (      
        <canvas id={this.state.Id} width="600" height="67"></canvas>
    );
  }

canvas需要获取Id,如果这样动态赋值id,componentDidMount或者componentDidUpdate中都拿不到canvas的ID,

var canvas = document.getElementById(this.state.Id);

需求是会有多个canvas组件

https://img3.mukewang.com/5b54915c0001ae0e08000660.jpg

这种情况下,该如何绘制动画?


LEATH
浏览 1945回答 3
3回答

慕尼黑5688855

&nbsp; drawCanvas = canvas => {&nbsp; &nbsp; if (!canvas) { return }&nbsp; &nbsp; // ....&nbsp; }&nbsp; render() {&nbsp; &nbsp; return (&nbsp; &nbsp; &nbsp; <canvas ref={drawCanvas} width="600" height="67"></canvas>&nbsp; &nbsp; );&nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP