简体   繁体   English

reactjs 中的 img 标签未显示在渲染器上

[英]img tag in reactjs is not displaying on render

The img tag in the following code is not showing any image.以下代码中的img标签未显示任何图像。 I have tried doing it in a bunch of ways like <img src="./bg.jpg" alt=""/> or writing the whole path but it's not working at all.我试过用很多方法来做,比如<img src="./bg.jpg" alt=""/>或写整个路径,但它根本不起作用。 I have also tried the backend for the image and different images bu the result is still the same.我也尝试了图像和不同图像的后端,但结果仍然相同。

import React from 'react';
import './VideoCard.css'
const base_url = "https://image.tmdb.org/t/p/original/";
function VideoCard({movie}) {
    return (
        <div className="videoCard">
            
            <img src="bg.jpg" alt=""/>
            <p>This is a film abt coding</p>
            <h2>Movie Title</h2>
            <p>Nuber of likes</p>
        </div>
    )
}
export default VideoCard

I think you need to first import your image file.我认为您需要先导入图像文件。

Try:尝试:

import React from 'react';
import './VideoCard.css'
import myImg from './bg.jpg';                               // <--- add this
const base_url = "https://image.tmdb.org/t/p/original/";
function VideoCard({movie}) {
    return (
        <div className="videoCard">
            
            <img src={myImg} alt=""/>               {/* <--- reference import here */}
            <p>This is a film abt coding</p>
            <h2>Movie Title</h2>
            <p>Nuber of likes</p>
        </div>
    )
}
export default VideoCard

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM