reactjs 我刚刚部署了我的Vite React站点,但我的图标/图像尚未部署

svdrlsy4  于 2022-12-26  发布在  React
关注(0)|答案(2)|浏览(161)

我在Netlify上部署了我的Vite React站点,但是我的技能图标没有呈现!!x1c 0d1x Here's the site.。我在部署之前执行了npm run build,我得到了dist文件夹并将其部署在Netlify上。但是一开始assets文件夹没有图标,所以我也将其添加到了assets(dist文件夹)文件夹中,但是没有成功!!请帮助。
我想使我的技能图标我的投资组合网站。

3zwtqj6y

3zwtqj6y1#

你需要把你的assets目录移到public目录,并且你需要从不同img文件的源路径中删除./src

{
    id: 1,
    icon: "/assets/html5.svg",
    iconName: "HTML",
},
c9qzyr3d

c9qzyr3d2#

参考Vite文档,您应将您的资产文件直接放入public文件夹。
请注意:
您应该始终使用根绝对路径引用公共资产-例如,public/icon.png应该在源代码中引用为/icon.png

    • 文件夹和文件**结构:

    • 技能. jsx**(* 图标 *)
import React from "react";
// import Skill from "./Skill";

function Skills() {
  return (
    <>
      <section className="skills">
        <div className="card">
          <div className="content">
            <img className="skillIcon" src="/html5.svg" alt="Icon" />
            <p className="skillName">HTML</p>
          </div>
          <div className="content">
            <img className="skillIcon" src="/css3.svg" alt="Icon" />
            <p className="skillName">CSS3</p>
          </div>
          <div className="content">
            <img className="skillIcon" src="/js.svg" alt="Icon" />
            <p className="skillName">JavaScript</p>
          </div>
          <div className="content">
            <img className="skillIcon" src="/react.svg" alt="Icon" />
            <p className="skillName">ReactJs</p>
          </div>
          <div className="content">
            <img className="skillIcon" src="/mongodb.svg" alt="Icon" />
            <p className="skillName">MongoDB</p>
          </div>
          <div className="content">
            <img className="skillIcon" src="/express.svg" alt="Icon" />
            <p className="skillName">ExpressJs</p>
          </div>
          <div className="content">
            <img className="skillIcon" src="/github.svg" alt="Icon" />
            <p className="skillName">GitHub</p>
          </div>
          <div className="content">
            <img className="skillIcon" src="/node.svg" alt="Icon" />
            <p className="skillName">NodeJs</p>
          </div>
          <div className="content">
            <img className="skillIcon" src="/password.svg" alt="Icon" />
            <p className="skillName">Authentication</p>
          </div>
          <div className="content">
            <img className="skillIcon" src="/api.svg" alt="Icon" />
            <p className="skillName">API</p>
          </div>
        </div>
      </section>
    </>
  );
}

export default Skills;
    • jsx简介**(* 英雄. gif *)
import React from "react";
import hero from "/hero.gif";
function Intro() {
  return (
    <>
      <main>
        <section id="intro" className="hero">
          <div className="heroText">
            <p className="topData">Hey, I'm</p>
            <h1 className="title">Shubham Pawar</h1>
            <p className="heroData">I'm a MERN stack Developer.</p>
            <button className="btn">Contact Me</button>
            <button className="btn">Resume</button>
          </div>
          <div className="heroImg">
            <img className="heroGif" src={hero} alt="hero img" />
          </div>
        </section>
      </main>
    </>
  );
}

export default Intro;
    • 页脚. jsx**(* 图标 *)
import React from "react";

function Footer() {
  return (
    <>
      <footer className="Footer">
        <div className="footer-right">
          <a href="#"></a>
          <a href="#">
            <img className="footerIcon" src="/linkedin2.png" alt="linkedIn" />
          </a>
          <a href="#">
            <img className="footerIcon" src="/github2.png" alt="GitHub" />
          </a>
          <a href="#">
            <img className="footerIcon" src="/instagram.png" alt="Instagram" />
          </a>
          <a href="#">
            <img className="footerIcon" src="/twitter.png" alt="Twitter" />
          </a>
        </div>

        <div className="footer-left">
          <p className="footer-links">
            <a className="link-1" href="#">
              Home
            </a>

            <a href="#about">About</a>

            <a href="#contact">Contact</a>
          </p>
          <p>
            @mjshubham21 Copyright &copy; {new Date().getFullYear()} All Rights
            Reserved.
          </p>
        </div>
      </footer>
    </>
  );
}

export default Footer;
    • 在浏览器中输出**:

相关问题