V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
dong3580
V2EX  ›  React

reactjs 组件如何复用?

  •  
  •   dong3580 · Dec 1, 2015 · 2225 views
    This topic created in 3809 days ago, the information mentioned may be changed or developed.

    并未看懂这篇文档 里面的重用组件。
    掳了掳代码,想在 example1 和 example2 上分别附上该组件

    http://jsbin.com/vivufo/edit?html,js,output

    不知如何在 另一个 div  上复用?

    1 replies    2015-12-02 14:56:18 +08:00
    dong3580
        1
    dong3580  
    OP
       Dec 2, 2015
    已经解决。
    看到有人收藏,给以后的童鞋回复一下:

    React.render 复用组件最外层只能有一级节点,所以如果需要输入多个<TweetBox/>控件,则需要

    React.render(
    <div><TweetBox /><TweetBox/></div>, document.getElementById("example1")
    );

    用 div 或其它 包装成一级节点 就行了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   892 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 21:44 · PVG 05:44 · LAX 14:44 · JFK 17:44
    ♥ Do have faith in what you're doing.