具有 CardImg 的线路存在一些问题。它显示错误:
'TypeError: Cannot read property 'image' of undefined'.
我无法弄清楚我做错了什么。请帮帮我。
有错误的类在这里:
import React from 'react';
import {Card, CardImg, CardText, CardBody, CardTitle, CardSubtitle} from 'reactstrap';
import {Loading} from "./LoadingComponent";
import { baseUrl } from '../shared/baseUrl';
function RenderCard({item, isLoading, errMess}){
if (isLoading) {
return(
<Loading />
);
}
else if (errMess) {
return(
<h4>{errMess}</h4>
);
}
else
return(
<Card>
<CardImg src={baseUrl + item.image} alt={item.name} />
<CardBody>
<CardTitle>{item.name}</CardTitle>
{item.designation ? <CardSubtitle>{item.designation}</CardSubtitle> : null}
<CardText>{item.description}</CardText>
</CardBody>
</Card>
);
}
function Home(props){
return(
<div className="container">
<div className="row align-items-start">
<div className="col-12 col-md m-1">
<RenderCard item={props.dish} isLoading={props.dishesLoading}
errMess={props.dishesErrMess}/>
</div>
<div className="col-12 col-md m-1">
<RenderCard item={props.promotion} isLoading={props.promosLoading} errMess={props.promosErrMess} />
</div>
<div className="col-12 col-md m-1">
<RenderCard item={props.leader}/>
</div>
</div>
</div>
);
}
export default Home;
答案 0 :(得分:0)