猿问

如何定义背景滑块的背景以及如何修复它?

我正在尝试为餐厅制作背景滑块。出于这个原因,我使用了 gatsby-image-background-slider。当我执行“gatsby develop”时,它在执行时没有显示错误,但是当我尝试在本地主机中浏览时,它显示错误“× TypeError:无法读取未定义的属性'背景'”

源代码可以在这里找到在这里输入链接描述

我想使用轮播,但我认为使用这个插件会更好。这是我在 gatsby 的第一次尝试。我已经安装了插件并尝试了 graphql 中的查询。根据 gatsby-image-background-slider 文档,没有提到将目录提供给背景。我尝试在相对路径中输入一些内容,但它显示错误并且文档中未提及。

有什么想法我怎样才能摆脱这个错误或者我可以有一个背景滑块或旋转木马之类的优化方式吗?


叮当猫咪
浏览 148回答 2
2回答

海绵宝宝撒

如果您指定要包含的图像 (images={[]}),请确保图像名称存在于您的图像文件夹中

冉冉说

您需要将 BackgroundSection 组件更改为:export default function BackgroundSection({&nbsp; img,&nbsp; styleClass,&nbsp; children,&nbsp; title,&nbsp; query // you forgot this}) {&nbsp; return (&nbsp; &nbsp; <BackgroundSlider className={styleClass} fluid={img} query={query}>&nbsp; &nbsp; &nbsp; <div class="container">&nbsp; &nbsp; &nbsp; &nbsp; <div class="row align-items-center justify-content-center">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="col-xl-9 col-md-9 col-md-12">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="slider_text text-center bold">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <h1>{title}</h1>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <h1>{title}</h1>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; {children}&nbsp; &nbsp; </BackgroundSlider>&nbsp; )}您忘记包含查询并将该查询传递给 BackgroundSLider 组件
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答