react 组件之间的参数传递

const MessageBox = React.createClass({
            getInitialState:function() {
                return {
                    title: 'props属性传值',
                    messages: ['messages1','messages2','messages3','messages4']
                }
            },
            render: function () {
                return (
                    

我是子组件1

{this.state.title}

this.state.messages}/>
) } }); const SubMessageBox = React.createClass({ propTypes: { // 声明数据类型 messages: React.PropTypes.array.isRequired }, getDefaultProps: function(){ return { messages: ['若未传message,会报未定义,故此这里定义一个默认值,即使为空数组也行,但一定要定义'] } }, render:function() { {/* let messages = []; this.props.messages.forEach(function(msg,index) { console.log(msg); messages.push(msg) }); console.log(this.props.messages)*/} return(

我是子组件2

{this.props.messages}

this.props.messages} />
) } }) const Footer = React.createClass({ render:function() { let messages = []; this.props.messages.forEach(function(msg,index) { msg += index messages.push(msg) }); return (

我是子组件3

{messages}

) } }) const MessageBoxObj = React.render( , document.getElementById('app'), function() { console.log('渲染完成'); } );

你可能感兴趣的:(js,React)