自定义分页滑块缺少react.js的配置文件

时间:2018-10-16 15:58:36

标签: javascript css reactjs slider custompaging

我正在从https://react-slick.neostack.com/docs/example/custom-paging/创建自定义分页滑块,我直接从网站复制了代码,并按照说明进行操作并安装了软件包。当我尝试运行代码时,出现以下错误:

./ src / Carousel.js 找不到模块:无法解析'/ Users / mcoe / Documents / Code / my-app1 / src'中的'./config.js'

代码:

import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import Style from "react-responsive-carousel/lib/styles/carousel.min.css";
import { Carousel } from 'react-responsive-carousel';
import Slider from 'react-slick';
import { baseUrl } from "./config.js";

export default class SimpleSlider extends React.Component {
  render() {
    const settings = {
      customPaging: function(i) {
        return (
          <a>
            <img src={`${baseUrl}"Random1${i + 1}.png`} />
          </a>
        );
      },
      dots: true,
      dotsClass: "slick-dots slick-thumb",
      infinite: true,
      speed: 500,
      slidesToShow: 1,
      slidesToScroll: 1
    };
    return (
      <div>
        <h2>Custom Paging</h2>
        <Slider {...settings}>
          <div>
            <img src={baseUrl + "Random1.png"} />
          </div>
          <div>
            <img src={baseUrl + "Random1.png"} />
          </div>
          <div>
            <img src={baseUrl + "Random1.png"} />
          </div>
          <div>
            <img src={baseUrl + "Random1.png"} />
          </div>
        </Slider>
      </div>
    );
  }
}

2 个答案:

答案 0 :(得分:0)

该组件似乎只需要配置文件中的基本URL。 baseUrl必须是图片的网址路径。相对路径应该起作用,因此,如果将它们存储在my-app1/public/images/中,则应该能够在config.js目录中创建文件src,如下所示:

//config.js
export const baseUrl = 'images/';

答案 1 :(得分:0)