错误:类型错误:无法读取未定义的属性“图像”

时间:2021-07-28 18:47:29

标签: reactjs image properties undefined typeerror

具有 CardImg 的线路存在一些问题。它显示错误:
'TypeError: Cannot read property 'image' of undefined'.

我无法弄清楚我做错了什么。请帮帮我。

这是错误的样子: enter image description here

有错误的类在这里:

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;