react-踩坑记录——swiper报错!
已经在html文件中使用过,正确无误;但做成组件后(各种依赖文件引入路径确认无误)报错。
在只引入swiper.css时未报错,引入swiper.js文件后报错,如下:
错误原因,不详。
解决措施,不引入swiper.js,而是直接npm install swiper,在文件头部导入,如⬇️:
import React, { Component } from 'react'; import logo from './logo.svg'; import '../src/css/reset.css'; import '../src/css/swiper.css'; import '../src/css/slider.css'; import Swiper from 'swiper'; class Slider extends Component { constructor(){ super(); this.state = { }; } componentDidMount(){ var swiper = new Swiper('.swiper-container', { pagination: '.swiper-pagination', nextButton: '.swiper-button-next', prevButton: '.swiper-button-prev', paginationClickable: true, spaceBetween: 30, centeredSlides: true, autoplay: 2500, autoplayDisableOnInteraction: false }); } render(){ return <div className="swiper-container"> <div className="swiper-wrapper"> <div className="swiper-slide">Slide 1</div> <div className="swiper-slide">Slide 2</div> <div className="swiper-slide">Slide 3</div> <div className="swiper-slide">Slide 4</div> </div> <div className="swiper-pagination"></div> <div className="swiper-button-next"></div> <div className="swiper-button-prev"></div> </div> } } class App extends Component { render(){ return <div> <Slider></Slider> </div> } } export default App;
这时又出现了新问题,写在html 文件中预览时还能自动轮播的图片,拆成组件后只能手划动轮播。。。待解
怕什么真理无穷,进一寸有一寸的欢喜。