Help with dynamic images in Reactjs

Asked

Viewed 281 times

0

inserir a descrição da imagem aqui> My code is returning the string value in the console, but does not return the image even though the path is right in the scr. I do not know what my mistake.I ask for help I am new in language. below is my code:

import React from 'react';
import '../../App.css';
import Servico from './servico';
import Card from 'react-bootstrap/Card';
import CardDeck from 'react-bootstrap/CardDeck';

function ServicesList() {

  return (
   <div>
           {Servico.Servico.map((servicoDetail,)=>{
               return <div key={servicoDetail.Posicao}>
               <CardDeck>
                 <Card>
                   
                 <Card.Img variant="top" src={servicoDetail.Imagem} alt={servicoDetail.Imagem} />
                 <Card.Body>
                 <Card.Title>{servicoDetail.Titulo}</Card.Title>
                 <Card.Subtitle className="mb-2 text-muted">{servicoDetail.Subtitulo}</Card.Subtitle>
                 <Card.Text>
                   This is a wider card with supporting text below as a natural lead-in to
                   additional content. This content is a little bit longer.
                 </Card.Text>
                 </Card.Body>
                  
                </Card>
              </CardDeck>
</div>

           })}
    </div>
      );
}

export default ServicesList;

  • How the image URL is coming?

  • as much as .. /image.png as image.png n can set to work.

  • If you put the string value statically inside the src, it appears? It seems to me a server problem, you have a static route to access the images?

  • putting the static path works, these images are on my computer.

  • Are the images inside your project’s src/ or in another directory of your computer? I ask this because they must be served by a web server to function properly

  • Company staff gave me a local json.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.