我正在使用 ReactJs。我有两个组件,PrescriptionIndex 和 PrescriptionNew,它们相互集成。
这是我的第一个组件“PrescriptionNew”
import React, { Component } from 'react';
import FloatingActionButton from 'material-ui/FloatingActionButton';
import ContentAdd from 'material-ui/svg-icons/content/add';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'
class PrescriptionNew extends Component {
render(){
return(
<div>
<MuiThemeProvider>
<FloatingActionButton mini={true} style={{"color": "pink"}}>
<ContentAdd/>
</FloatingActionButton>
</MuiThemeProvider>
</div>
)
}
}
export default PrescriptionNew;
这是我的另一个组件“PrescriptionIndex”
import React , { Component } from 'react';
import { connect } from "react-redux";
import { fetchPrescriptionFromUrl } from '../actions/index.js';
import { Link } from 'react-router';
import PrescriptionNew from './new.jsx';
import '../app.css';
class PrescriptionIndex extends Component {
componentDidMount(){
this.props.fetchData(PORT+'/prescriptions');
}
render() {
if (this.props.has_error){
return(<p> Fetching an Api results in error</p>)
}
if (this.props.has_loading){
return(<p> Loading...</p>)
}
if (this.props.prescriptions.prescriptions !== undefined) {
return this.props.prescriptions.prescriptions.map(function(data){
return (
<div className="image-prescription" key={data.id}>
<Link to={"/update/" + data.id} >
<img src={data.image_path.image_path.url}
className="prescription-image"
alt="prescription"
/>
</Link>
</div>
);
});
} else {
return null;
}
return(
<div>
<PrescriptionNew /> //this is where I need my another component
</div>
)
}
}
export default PrescriptionIndex;
在运行时,“PrescriptionNew”组件不可见。在检查控制台时,警告被声明为“无法访问的代码”。我已经通过其他解决方案,但我无法研究我的代码出了什么问题。