当前位置: 首页 > 知识库问答 >
问题:

不在浏览器中显示图像

楚昊明
2023-03-14

我有一个小React项目。当我从infosection.elements.js调用一个属性时,不幸的是,浏览器中只显示alt部分,而不显示图像本身。请帮助我显示这个代码的图像。非常感谢。

app.js

import React from "react";
import GlobalStyle from "./globalStyles";
import Home from "./pages/HomePage/Home";
import { BrowserRouter as Router, Switch, Route } from "react-router-dom";
import { Navbar } from "./components";

function App() {
  return (
    <Router>
      <GlobalStyle />
      <Navbar />
      <Switch>
        <Route path="/" exact component={Home} />
      </Switch>
    </Router>
  );
}

export default App;

data.js:

export const homeObjOne = {
  primary: true,
  lightBg: false,
  lightTopLine: true,
  lightText: true,
  lightTextDesc: true,
  topLine: "Marketing Agency",
  headline: "Lead Generation Specialist for Online Businesses",
  description:
    "We help business owners increase their revenue. Our team of unique specialist can help you achieve your business goals.",
  buttonLabel: "Get Started",
  imgStart: "",
  img: require("../../images/svg-1.svg"),
  alt: "Credit Card",
  start: "",
};

export const homeObjTwo = {
  primary: true,
  lightBg: false,
  lightTopLine: true,
  lightText: true,
  lightTextDesc: true,
  topLine: "Instant Setup",
  headline: "Extremely quick onboarding process",
  description:
    "Once you've joined, our team of specialist will reach out to you and get you set up in minutes.",
  buttonLabel: "Learn More",
  imgStart: "",
  img: require("../../images/svg-2.svg"),
  alt: "Vault",
  start: "",
};

export const homeObjThree = {
  primary: false,
  lightBg: true,
  lightTopLine: false,
  lightText: false,
  lightTextDesc: false,
  topLine: "Sarah Jeni",
  headline:
    "Ultra helped me increase my revenue by over 3X in less than 3 months!",
  description:
    "Their team is wonderful! I can't believe I didn't start working with them earlier.",
  buttonLabel: "View Case Study",
  imgStart: "start",
  img: require("../../images/profile.jpg"),
  alt: "Vault",
  start: "true",
};

export const homeObjFour = {
  primary: true,
  lightBg: false,
  lightTopLine: true,
  lightText: true,
  lightTextDesc: true,
  topLine: "Secure Database",
  headline: "All your data is stored on our secure server",
  description:
    "You will never have to worry about your information getting leaked. Our team of security experts will ensure your records are kept safe.",
  buttonLabel: "Sign Up Now",
  imgStart: "start",
  img: require("../../images/profile.jpg"),
  alt: "Vault",
  start: "true",
};

home.js:

import React from "react";
import { homeObjOne, homeObjTwo, homeObjThree, homeObjFour } from "./Data";
import { InfoSection } from "../../components";

function Home() {
  return (
    <>
      <InfoSection {...homeObjOne} />
      <InfoSection {...homeObjThree} />
      <InfoSection {...homeObjTwo} />
      <InfoSection {...homeObjFour} />
    </>
  );
}

export default Home;

infosection.js:

import React from "react";
import { Link } from "react-router-dom";
import { Container, Button } from "../../globalStyles";
import {
  InfoSec,
  InfoRow,
  InfoColumn,
  TextWrapper,
  TopLine,
  Heading,
  Subtitle,
  ImgWrapper,
  Img,
} from "./InfoSection.elements";

function InfoSection({
  primary,
  lightBg,
  topLine,
  lightTopLine,
  lightText,
  lightTextDesc,
  headline,
  description,
  buttonLabel,
  img,
  alt,
  imgStart,
  start,
}) {
  return (
    <>
      <InfoSec lightBg={lightBg}>
        <Container>
          <InfoRow imgStart={imgStart}>
            <InfoColumn>
              <TextWrapper>
                <TopLine lightTopLine={lightTopLine}>{topLine}</TopLine>
                <Heading lightText={lightText}>{headline}</Heading>
                <Subtitle lightTextDesc={lightTextDesc}>{description}</Subtitle>
                <Link to="/sign-up">
                  <Button big fontBig primary={primary}>
                    {buttonLabel}
                  </Button>
                </Link>
              </TextWrapper>
            </InfoColumn>
            <InfoColumn>
              <ImgWrapper start={start}>
                <Img src={img} alt={alt} />
              </ImgWrapper>
            </InfoColumn>
          </InfoRow>
        </Container>
      </InfoSec>
    </>
  );
}

export default InfoSection;

infosection.elements.js:

import styled from "styled-components";

export const InfoSec = styled.div`
  color: #fff;
  padding: 160px 0;
  background: ${({ lightBg }) => (lightBg ? "#fff" : "#101522")};
`;

export const InfoRow = styled.div`
  display: flex;
  margin: 0 -15px -15px -15px;
  flex-wrap: wrap;
  align-items: center;
  flex-direction: ${({ imgStart }) => (imgStart ? "row-reverse" : "row")};
`;

export const InfoColumn = styled.div`
  margin-bottom: 15px;
  padding-right: 15px;
  padding-left: 15px;
  flex: 1;
  max-width: 50%;
  flex-basis: 50%;

  @media screen and (max-width: 768px) {
    max-width: 100%;
    flex-basis: 100%;
    display: flex;
    justify-content: center;
  }
`;

export const TextWrapper = styled.div`
  max-width: 540px;
  padding-top: 0;
  padding-bottom: 60px;

  @media screen and (max-width: 768px) {
    padding-bottom: 65px;
  }
`;

export const ImgWrapper = styled.div`
  max-width: 555px;
  display: flex;
  justify-content: ${({ start }) => (start ? "flex-start" : "flex-end")};
`;

export const TopLine = styled.div`
  color: ${({ lightTopLine }) => (lightTopLine ? "#a9b3c1" : "#4B59F7")};
  font-size: 18px;
  line-height: 16px;
  font-weight: 700;
  letter-spacing: 1.4px;
  margin-bottom: 16px;
`;

export const Img = styled.img`
  padding-right: 0;
  border: 0;
  max-width: 100%;
  vertical-align: middle;
  display: inline-block;
  max-height: 500px;
`;

export const Heading = styled.h1`
  margin-bottom: 24px;
  font-size: 48px;
  line-height: 1.1;
  font-weight: 600;
  color: ${({ lightText }) => (lightText ? "#f7f8fa" : "#1c2237")};
`;

export const Subtitle = styled.p`
  max-width: 440px;
  margin-bottom: 35px;
  font-size: 18px;
  line-height: 24px;
  color: ${({ lightTextDesc }) => (lightTextDesc ? "#a9b3c1" : "#1c2237")};
`;

共有1个答案

艾泉
2023-03-14

我假设您使用create-react-app作为样板。如果是:

>

然后您可以将data.js/code>中的 更改为br>

如果没有必要,我会避免

 类似资料:
  • 我有一个从数据库中检索图像路径的程序。程序正在eclipse浏览器中成功检索图像,但未在任何web浏览器中检索。我有3页,第一页。登录名。jsp 2。指数jsp 3。LoginServlet。Java语言

  • 我正面临一个奇怪的问题。我已经把所有东西都放在php.ini文件里了。但是我不能在浏览器中显示任何错误。我google设置了. ini文件,并做了所有需要的事情。但是我仍然不能在浏览器中显示错误信息。我的PHP ini设置, 我尝试使用以下代码查看错误消息, 实际上文件示例不可用。所以它必须显示致命错误。但它显示的是空白页。 你能告诉我怎么解决这个问题吗?我不知道我错过了什么。

  • 问题内容: 我终于设法让我的Java小程序在浏览器中运行,但是现在我面临一个问题,那就是我的图像都不会显示。唯一显示的是在applet屏幕中绘制的黑色文本。 为了使该applet完全起作用,我不得不将其作为罐子导出并自己签名。现在,我想知道为什么图像无法显示。我检查了一下,jar文件确实包含了所有图像文件。同样,小程序在Eclipse中运行得很好。 这可能是什么问题? 是应该访问的第一个图像。 另

  • 问题内容: 如何处理HTML页面中的TIFF文件? 我想在HTML页面中显示TIFF文件。 我尝试使用嵌入式标签,对象ID,IMG等。但是我无法在HTML页面中显示图像(TIFF)。 我在项目中没有使用Java,.NET或其他任何东西。我仅使用HTML。 更新:Safari支持TIFF图像加载。如何在其他浏览器(IE,Mozilla,Firefox等)中加载TIFF图像? 我无法安装第三方插件或控

  • 受保护的void doPost(HttpServletRequest请求,HttpServletResponse响应)抛出ServletException,IOException{ } 在Eclipse中,内部web浏览器如下所示(下图) Eclipse内部web浏览器的打印屏幕

  • 问题内容: 如何在Web浏览器中的.html页面上显示pdf? 问题答案: 我使用的是Google文档可嵌入的PDF查看器。这些文档不必上传到Google文档,但必须在线提供。

  • 我有一个java类,当我们运行时,会执行一个批处理文件。我有一个变量(布尔值),它将显示true或false,指示批处理文件是否正确执行其命令。现在,true或false输出只显示在控制台中。我希望在键入URL时,它会显示在web浏览器上(例如,) 到目前为止,我有以下代码: 运行批处理文件。JAVA BatchFile.java 这个批处理文件。Java类给了我以下错误: JAVA异常:测试类在

  • 我在SpringBoot api上工作,并使用具有以下属性设置的H2数据库。 当我想使用浏览器通过'http://localhost:8082/h2-console'查看H2数据库控制台时,浏览器中打开了一个带有连接和测试连接按钮的屏幕。当我单击Test Connection时,它返回成功,但当单击Connect按钮时,出现错误,即localhost拒绝连接。