首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有Gatsby + Contentful + react响应式旋转木马的英雄横幅旋转木马

带有Gatsby + Contentful + react响应式旋转木马的英雄横幅旋转木马
EN

Stack Overflow用户
提问于 2020-02-02 22:42:27
回答 1查看 726关注 0票数 0

尝试使用最流行的"Slider carousel“包之一,但想不出如何在Gatsby + Contentful的静态站点设置中使用它。我正尝试在本地运行这段代码。

代码语言:javascript
复制
import React from 'react';
import { makeStyles } from '@material-ui/core/styles/';
import BackgroundImage from 'gatsby-background-image';
import 'react-responsive-carousel/lib/styles/carousel.min.css';
import { Carousel } from 'react-responsive-carousel';
import Img from 'gatsby-image';

const useStyles = makeStyles(theme => ({
  heroImage: {
    height: '80vh',
  },
}));

const HeroCarousel = ({ data }) => {
  const classes = useStyles();

  return (
    <Carousel>
      <div>
        <BackgroundImage
          fluid={data.heroImage.fluid}
          className={classes.heroImage}
        />
        {/* <Img fluid={data.heroImage.fluid} className={classes.heroImage} /> */}
      </div>
      <div>
        <BackgroundImage
          fluid={data.heroImage.fluid}
          className={classes.heroImage}
        />
        {/* <Img fluid={data.heroImage.fluid} className={classes.heroImage} /> */}
      </div>
    </Carousel>
  );
};

export default HeroCarousel;

Contentful here的查询终结点以前工作过的父级:

代码语言:javascript
复制
...
const RootIndex = ({ data }) => {
  const [author] = data.allContentfulPerson.edges;
  const news = data.allContentfulBlogPost.edges;
  return (
    <>
      <HeroCarousel showThumbs={false} data={author.node} /> *Here is the component*
      {/* <HeroBanner data={author.node} /> */}
    </>
  );
};

export default RootIndex;

export const pageQuery = graphql`
  ...

EN

回答 1

Stack Overflow用户

发布于 2020-02-03 03:29:41

已修复。不妨把这个问题留在这里,因为这可能是服务器端渲染站点上的图像滑块的一个很好的设置,而且gatsby-image内置了一些强大的图像优化功能。

这个小补丁起作用了:

代码语言:javascript
复制
<Carousel showThumbs={false}>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60027170

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档