如何在reactjs中扩展多个类子组件?
//this is one component
import React from 'react';
import ReactDOM from 'react-dom';
import axios from 'axios';
class Apicomponent extends React.Component{
constructor(){
super();
this.sate={};
this.ibios=this.ibios.bind(this);
}
ibios(e){
var prametars={
"firstName":"venkaiah"
}
return prametars;
}
render(){
return(
<p>hi...</p>
);
}
}
export default Apicomponent;
//another component
import React from 'react';
import ReactDOM from 'react-dom';
import Apicomponent from './IBIOS';
class IbiosGetComponent extends Apicomponent{
constructor(){
super();
this.sate={};
this.apiCallFunction=this.apiCallFunction.bind(this);
}
apiCallFunction(){
var apCallfunction=this.ibios();
}
render(){
return(
<p>hi...</p>
);
}
}
export default IbiosGetComponent;
//如何扩展多个类
import React from 'react';
import ChartComponent from './ChartComponents';
import IbiosGetComponent from '../IBIOS/ApiCalls';
class BarChartComponent extends ChartComponent,IbiosGetComponent{
constructor(props){
super(props)
this.state={}
}
componentDidMount(){
var parmsfromibios=this.IbiosGetComponent.apiCallFunction();
console.log(parmsfromibios)
}
render(){
return(<p>hi....</p>)
}
export default BarChartComponent;
答案 0 :(得分:0)
你应该使用关键字'super'来访问继承的类
apiCallFunction(){
var apCallfunction = super.ibios();
}