React <img src="#"/> 标签在浏览器中不显示图像

哈里斯·艾哈迈德 |

你好,这似乎是基本的,但我迷路了。

标签在浏览器中显示图像的替代名称,但不显示图像。

这是该部分的图像和代码。

在此处输入图片说明

标志是它的位置,但不显示标志的图像。

投资组合.js

const educationInfo = {
    display: true,
    schools : [
        {
            schoolName : "University of Engineering and Technology, Peshawar",
            logo: require("./assets/images/uet.png"),
            subHeader : "Bachelor of Electrical and Electronics Engineering",
            duration : "Aug 2016 to Oct 2020",
            desc : "Completed Bachelors with good grades, participated in multiple small 
               projects and successfully completed FYP on Commercial scale",
            descBullets : ["FYP: Raspberry-Pi based Cheque and Cash Deposit machine with 
               digital Wallet"]
         },
       ]
    };

教育卡.js

import React,{createRef, useContext} from 'react'
import './EducationCard.css';
import StyleContext from '../../contexts/StyleContext';
import { Slide, Rotate } from 'react-reveal';
import { educationInfo } from '../../portfolio';

export default function EducationCard({school}){
     const {isDark } = useContext(StyleContext);
     const imgRef = createRef();
        
       #//..............

      <div className="education-card-left">
          <img
             crossOrigin={"anonymous"}
             ref={imgRef}
             className="education-roundedimg"
             src={educationInfo.schools.logo}
             alt={educationInfo.schools.schoolName}
             />
      </div>
舒班卡

require物体的内部是闻所未闻的。您可以尝试以下几点:

  1. 需要/在顶部导入您的图像。在对象内部使用它。

投资组合.js


import Logo from "./assets/images/uet.png";

const educationInfo = {
    display: true,
    schools : [
        {
            schoolName : "University of Engineering and Technology, Peshawar",
            logo: Logo,
            subHeader : "Bachelor of Electrical and Electronics Engineering",
            duration : "Aug 2016 to Oct 2020",
            desc : "Completed Bachelors with good grades, participated in multiple small 
               projects and successfully completed FYP on Commercial scale",
            descBullets : ["FYP: Raspberry-Pi based Cheque and Cash Deposit machine with 
               digital Wallet"]
         },
       ]
    };

否则,您可以做的是使用eval,例如:


const educationInfo = {
    display: true,
    schools : [
        {
            schoolName : "University of Engineering and Technology, Peshawar",
            logo: eval('require("./assets/images/uet.png")'),
            subHeader : "Bachelor of Electrical and Electronics Engineering",
            duration : "Aug 2016 to Oct 2020",
            desc : "Completed Bachelors with good grades, participated in multiple small 
               projects and successfully completed FYP on Commercial scale",
            descBullets : ["FYP: Raspberry-Pi based Cheque and Cash Deposit machine with 
               digital Wallet"]
         },
       ]
    };

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章