render() {
return (
<canvas id={this.state.Id} width="600" height="67"></canvas>
);
}canvas需要獲取Id,如果這樣動(dòng)態(tài)賦值id,componentDidMount或者componentDidUpdate中都拿不到canvas的ID,var canvas = document.getElementById(this.state.Id);需求是會(huì)有多個(gè)canvas組件這種情況下,該如何繪制動(dòng)畫(huà)?
3 回答

慕尼黑5688855
TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超2個(gè)贊
drawCanvas = canvas => {
if (!canvas) { return }
// ....
}
render() {
return (
<canvas ref={drawCanvas} width="600" height="67"></canvas>
);
}
添加回答
舉報(bào)
0/150
提交
取消