React中使用canvas画图没有效果

weixin_38058428 2018-09-30 02:59:45
结构是下面这样的,但是没有效果 import 。。。。。 class TradingCenter extends Component { constructor() { super(); } componentDidMount() { {localStorage.getItem('cookie_state') === '0'? ( this.draw() ) : ''} } draw = () => { var canvas = document.getElementById("canvas"); var ctx=canvas.getContext('2d'); ctx.fillRect(100, 100, 300, 150); ctx.fillStyle ="rgb(0, 0, 0, 0.6)"; ctx.fill(); ctx.strokeStyle = "red"; } render() { return( <div> {localStorage.getItem('cookie_state') === '0'? ( <canvas id="canvas" width={document.body.clientWidth} height={document.body.scrollHeight}></canvas> ) : ''} </div> ) } } export default myConnect( state => ({ ...state.tradingCenter, ...state.appConfig, mobile: state.userConfig.mobile, email: state.userConfig.email, precision: state.tokenConfig.precision, tokenMap: state.tokenConfig.tokenMap, tokenName: state.tokenConfig.tokenName, istransaction: state.tokenConfig.istransaction, tokenCNName: state.tokenConfig.tokenCNName }), dispatch => bindActionCreators(actions, dispatch) )(TradingCenter);
...全文
163 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复

473

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧