在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ react項目中,想往父組件Object-Container傳遞一個模塊,請問怎

react項目中,想往父組件Object-Container傳遞一個模塊,請問怎么傳遞?

Object-Container.js

import React from 'react';

/**
 * 描述:Echarts 外層構(gòu)造組件
 * 時間:2017年12月2日
 */

class Foundation extends React.Component {

    constructor() {
        super();
    }

    _init() {
        // 參數(shù)設(shè)置
        var doc = document.getElementsByClassName('cs001')[0]
        //var optionECharts = this.props.defaultProps;

    }

    componentDidMount() {
        this._init()
    }


    componentWillMount() {
        //this.showJson();
    }

    render() {
        return (
            <div className={'cs001'} style={{width: 800, height: 800}}>

            </div>
        )
    }
}

export default Foundation;

Object-01.js

import React from 'react';
import Foundation from './Object-Container';
import echarts from 'echarts';

class AbbottTest extends React.Component {
    constructor() {
        super();

        this.state = {
            width: 800,
            height:800,
            isRed: true,
            className01: 'data-ec1',
            classPosition01:{

            },
            className02: 'data-ec2',
            classPosition02:{

            },
            optionECharts: {
                new echarts
            }
        }


    }



    render() {
        var divStyle ={
            display: 'block',
            width: 500,
            height: 500
        }

        return (

            <div style={divStyle} className='data-line'>
                <Foundation defaultProps={this.state.optionECharts}
                />
            </div>


        )
    }
}

export default AbbottTest;
回答
編輯回答
疚幼

props.children

<div>
    {this.props.children}
</div>

<AbbottTest>
    <Foundation />
</AbbottTest>

this.props.chilren就像當(dāng)與 那個內(nèi)部的 <Foundation />了

反正React16之前是可以這樣寫, 好像16之后你可以用Portal。 Portal我也沒用過。

不知道你的defaultProps還有沒有效,我知道可以這樣寫

2018年8月11日 05:25