美文网首页工作生活
React中实现类似vue动态组件效果

React中实现类似vue动态组件效果

作者: 情有千千节 | 来源:发表于2019-06-29 17:22 被阅读0次

render

    {/* 动态组件 */}
        {
          this.state.showCom ? 
          <section className={style['full-screen']}>
            { this.showCom() }
          </section>
          : ''
        }
  showCom = () => {
    const name = this.state.comName
    switch (name) {
      case 'Course':
        return <Course/>
      default:
        break;
    }
  }

相关文章

网友评论

    本文标题:React中实现类似vue动态组件效果

    本文链接:https://www.haomeiwen.com/subject/fzwpcctx.html