Object-Container.js
import React from 'react';
/**
* 描述:Echarts 外层构造组件
* 时间:2017年12月2日
*/
class Foundation extends React.Component {
constructor() {
super();
}
_init() {
// 参数设置
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
this.props.chilren就像当与 那个内部的 <Foundation />了
反正React16之前是可以这样写, 好像16之后你可以用Portal。 Portal我也没用过。
不知道你的defaultProps还有没有效,我知道可以这样写