在create react应用程序中将图像直接加载到index.html时出现问题

在create react应用程序中将图像直接加载到index.html时出现问题,html,css,reactjs,create-react-app,Html,Css,Reactjs,Create React App,我希望有一个完整的html页面,然后是一个使用React的小部分。我知道有比使用CreateReact应用程序更好的方法,但目前我正在使用。文件目录就是这样 public index.html src assets images logo.png components index.js index.css 除了在header标记中添加内容之外,我没有接触太多原始index.html我希望在HTML中显示一个图

我希望有一个完整的html页面,然后是一个使用React的小部分。我知道有比使用CreateReact应用程序更好的方法,但目前我正在使用。文件目录就是这样

public
    index.html 
src
    assets
        images
            logo.png

    components 
    index.js
    index.css
除了在header标记中添加内容之外,我没有接触太多原始index.html我希望在HTML中显示一个图像,但目前它只显示alt文本。

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
  <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <meta name="theme-color" content="#000000" />
  <meta name="description" content="Web site created using create-react-app" />
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:100,300,400,700,900">
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lobster+Two:100,300,400,700,900">
  <link rel="apple-touch-icon" href="logo192.png" />
  <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
  <title>My website</title>
</head>

<body>
  <header class="header">
    <div class="logo-box">
      // I cannot display the image at this part, I am pretty sure the link is correct.
      <img src="/mywebsite/src/assets/images/logo.png" alt="Logo" class="logo"> 
    </div>
  </header>

  <div id="root"></div> // react section will go here
</body>
</html>

我的网站
//我不能在这部分显示图像,我很确定链接是正确的。
//我要去这里

运行npm start时是否尝试显示图像?如果是这样,您需要将资产移动到公用文件夹中,然后在localhost中引用它们

参考:


如果您计划在构建代码时捆绑和部署资产,我建议您通读一遍,因为create react app默认情况下使用webpack进行部署。

能否提供您得到的错误以及您试图实现的目标。没有错误,图像根本不显示,只显示alt文本。我只想在标题标签中添加一个图像,并将其显示在HTMLIf上如果您使用chrome,您可以打开开发者工具,右键单击img标签的源代码,并在新标签中打开它,这将帮助您确定链接是否正确。它仍然显示alt文本而不是Logo。您是否将资产移动到公用文件夹并尝试使用相对路径进行引用?我的index.css文件当前引用了
src/assets/images
中的一些图像,这意味着我可能需要创建
public/images
好。。让它变得很乱。也许我会看看你们建议的网页,希望我暂时不需要触摸网页,看起来很复杂哈哈