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

React + Astro + Contentful 环境下富文本图片无法渲染的问题求助

React + Astro + Contentful 环境下富文本图片无法渲染的问题求助

大家好,我现在在做一个基于React、Astro和Contentful的项目,遇到了个头疼的问题——富文本里的图片死活渲染不出来,文本和标题倒是正常显示的,求各位大佬帮忙看看!

我尝试使用@contentful/rich-text-react-renderer包中的documentToReactComponents函数来渲染富文本,文本和标题部分都能正常渲染,但内容里的图片就是不出现。

下面是我简化后的组件代码:

import { documentToReactComponents } from "@contentful/rich-text-react-renderer";

export const TrendingArticles: React.FC<TrendingArticlesProps> = ({ faqData, heading }) => {
  // ...
  return (
    <section>
      <div>
        {faqData.map((item, index) => (
          <div key={index}>
            <button>
              {documentToReactComponents(item.question)}
            </button>
            <div>
              {documentToReactComponents(item.answer)}
            </div>
          </div>
        ))}
      </div>
    </section>
  );
};

我在Contentful的富文本字段里已经正确插入了图片,但实际页面输出中完全看不到图片的痕迹,只有文本内容正常展示。

备注:内容来源于stack exchange,提问作者Alejandro Baranov

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.13 19:33:06