最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - React Slick slider map not showing slides? - Stack Overflow

programmeradmin2浏览0评论

I am facing the following problem, where the React Slick slider is not displaying my slides inside the map function. Tried multiple things, but keep getting empty values.

When i hardcode divs it works, but when i try to create them dynamic even when the exist the don't show up.

Can someone help?

My code:

  <Slider {...settings}>
    {this.props.home.fetched &&
      this.props.home.content.map(value => {
        return value.acf.slider_extends.map((value, index) => {
          return (
            <div>
              <h1>{value.project_titel}</h1>
              <p>{value.project_intro}</p>
              <span>{value.video_project}</span>
            </div>
          );
        });
      })}
  </Slider>

I am facing the following problem, where the React Slick slider is not displaying my slides inside the map function. Tried multiple things, but keep getting empty values.

When i hardcode divs it works, but when i try to create them dynamic even when the exist the don't show up.

Can someone help?

My code:

  <Slider {...settings}>
    {this.props.home.fetched &&
      this.props.home.content.map(value => {
        return value.acf.slider_extends.map((value, index) => {
          return (
            <div>
              <h1>{value.project_titel}</h1>
              <p>{value.project_intro}</p>
              <span>{value.video_project}</span>
            </div>
          );
        });
      })}
  </Slider>
Share Improve this question edited Oct 30, 2019 at 4:43 Evert 99.9k18 gold badges131 silver badges213 bronze badges asked Apr 4, 2019 at 11:45 WDPWDP 2951 gold badge5 silver badges15 bronze badges 1
  • you're missing the key attribute to the div – Sagar Jajoriya Commented Apr 4, 2019 at 11:54
Add a ment  | 

2 Answers 2

Reset to default 3

If the containing div or section of Slick has the property flex, than it can cause pictures to disappear.

import React, { Component } from 'react';
import Slider from 'react-slick';

class Home extends Component {

    constructor() {
        super();
        this.state = {
            sliders: [
                'http://img.nowrunning./content/movie/2014/Jagga-Jaso/wall_1024x768_01.jpg',
                'https://alchetron./cdn/Cocktail-2012-film-images-6dbd0ec2-2ea4-47aa-88fd-388cabed7f8.jpg',
                'http://media.glamsham./download/wallpaper/movies/images/z/zindagi-na-milegi-dobara-wallpaper-03-12x9.jpg']
        }
    }

    sliders() {
        return this.state.sliders.map(data => {
            return (
                <div key={data}>
                    <img alt="image" src={data} />
                </div>
            )
        });
    }

    render() {
        const settings = {
            dots: true,
            autoplay: true,
            autoplaySpeed: 4000,
            arrow: false
        }
        return (
            <div >
                <Slider {...settings}>
                    {this.sliders()}
                </Slider>
            </div>
        );
    }
}
export default Home;
发布评论

评论列表(0)

  1. 暂无评论