import React from 'react'
import { Foundation } from './foundation'
class BarAA extends React.Component {
constructor() {
super();
//localStorage.username='再见';
}
defaultProps = {
autoPlay: false,
maxLoops: 10
}
render() {
return (
<div>baraaaaaaa</div>
)
}
}
BarAA = Foundation(BarAA);
export default BarAA;
import React from 'react';
// HOC 工厂实现方法
export const Foundation = (WrappedComponent) => {
class NewComponent extends React.Component {
constructor() {
super();
}
_init() {
// 参数设置
var doc = document.getElementById('ec');
var optionECharts = {
title: {
text: 'ECharts 入门测试开始'
},
tooltip: {},
legend: {
data: ['销量']
},
xAxis: {
data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子", "无敌"]
},
yAxis: {},
series: [{
name: '销量',
type: 'bar',
data: [5, 20, 36, 10, 10, 20, 90]
}]
};
return import(/* webpackChunkName: "echarts" */ 'echarts').then(echarts => {
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('ec'));
// 指定图表的配置项和数据
var option = optionECharts;
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
}).catch(error => 'An error occurred while loading the component');
}
componentDidMount() {
console.log(this.defaultProps.maxLoops)
this._init()
}
componentWillMount() {
}
render() {
return (
<div>
<WrappedComponent { ...this.props } />
</div>
)
}
}
return NewComponent
}
export default Foundation;

修改了一下,依然找不到那个属性

import React from 'react'
import { Foundation } from './foundation'
class BarAA extends React.Component {
constructor() {
super();
//localStorage.username='再见';
this.state = {
defaultProps: {
autoPlay: false,
maxLoops: 10
}
}
}
render() {
return (
<div>baraaaaaaa</div>
)
}
}
BarAA = Foundation(BarAA);
export default BarAA;
import React from 'react';
// HOC 工厂实现方法
export const Foundation = (WrappedComponent) => {
class NewComponent extends React.Component {
constructor() {
super();
}
_init() {
// 参数设置
var doc = document.getElementById('ec');
var optionECharts = {
title: {
text: 'ECharts 入门测试开始'
},
tooltip: {},
legend: {
data: ['销量']
},
xAxis: {
data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子", "无敌"]
},
yAxis: {},
series: [{
name: '销量',
type: 'bar',
data: [5, 20, 36, 10, 10, 20, 90]
}]
};
return import(/* webpackChunkName: "echarts" */ 'echarts').then(echarts => {
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('ec'));
// 指定图表的配置项和数据
var option = optionECharts;
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
}).catch(error => 'An error occurred while loading the component');
}
showJson(){
var test;
if(window.XMLHttpRequest){
test = new XMLHttpRequest();
}else if(window.ActiveXObject){
test = new window.ActiveXObject();
}else{
console.log("请升级至最新版本的浏览器");
}
if(test !=null){
test.open("GET","./json.json",true);
test.send(null);
test.onreadystatechange=function(){
if(test.readyState==4&&test.status==200){
var obj = JSON.parse(test.responseText);
for (var name in obj){
console(obj[name].key);
}
}
};
}
}
componentDidMount() {
this._init()
}
componentWillMount() {
//this.showJson();
console.log(this.state.defaultProps)
}
render() {
return (
<div>
<WrappedComponent/>
</div>
)
}
}
return NewComponent
}
export default Foundation;
这种不是用props传递的吗?