You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

添加Experience组件后React网站仅显示背景的问题求助

问题排查与解决步骤

你的页面在添加Experience组件后仅显示灰色背景,核心问题集中在组件依赖缺失与第三方组件配置上,以下是具体排查和修复方案:

1. 修复缺失的组件导入

你的Experience组件中使用了<SectionTitle>,但未导入该组件,这会直接触发"SectionTitle is not defined"错误,导致React应用渲染失败。

修正方法:在Experience组件开头添加对应导入语句,与其他正常板块保持一致:

import React from "react"
import { Chrono } from "react-chrono";
// 新增SectionTitle组件导入
import SectionTitle from "../Components/SectionTitle";

2. 确认react-chrono依赖已安装

如果未安装react-chrono包,导入组件时会抛出模块找不到的错误,导致页面崩溃。执行以下命令安装依赖:

npm install react-chrono
# 或使用yarn
yarn add react-chrono

3. 导入react-chrono的样式文件

react-chrono需要手动引入内置样式,否则会出现布局错乱或组件不显示的问题,建议在组件中添加样式导入:

import React from "react"
import { Chrono } from "react-chrono";
import SectionTitle from "../Components/SectionTitle";
// 新增样式文件导入
import "react-chrono/styles.css";

4. 利用浏览器控制台定位错误

打开浏览器开发者工具(快捷键F12),切换到Console标签,这里会显示具体的错误信息(比如组件未定义、模块缺失等),是排查React渲染问题最直接的方式。

修正后的完整Experience组件代码

import React from "react"
import { Chrono } from "react-chrono";
import SectionTitle from "../Components/SectionTitle";
import "react-chrono/styles.css";

const Experience = () => {
  const items = [{
    title: "May 1940",
    cardTitle: "Dunkirk",
    url: "http://www.history.com",
    cardSubtitle:"Men of the British Expeditionary Force (BEF) wade out to..",
    cardDetailedText: "Men of the British Expeditionary Force (BEF) wade out to..",
    media: {
      type: "IMAGE",
      source: {
        url: "http://someurl/image.jpg"
      }
    }
  }]

  return (
    <div id="experience" className="w-full flex justify-center overflow-hidden-web">
      <div className="w-full xl:w-[70%] flex flex-col pb-16">
        <div className="w-full">
          <SectionTitle title="EXPERIENCE" subtitle="What I've Done Before" />
        </div>
        <div style={{ width: "500px", height: "400px" }}>
          <Chrono items={items} />
        </div>
      </div>
    </div>
  )
}

export default Experience;

按以上步骤修正后,页面即可正常渲染。若仍有问题,优先查看控制台错误提示,根据提示进一步排查。

内容的提问来源于stack exchange,提问作者maria xu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 12:15:26