React 使用 awesome-swiper 使用
安装包依赖
cnpm install react-awesome-swiper -S
使用
- 新建一个 style.less 文件,特别注意的就是必须要有 opacity
.swiperAll {
width: 100%;
height: 600px;
.swiper-wrapper {
width: 100%;
height: 100%;
}
.swiper-pagination {
opacity: 1 !important;
}
}
import AwesomeSwiper from 'react-awesome-swiper'
import './style.less'
class CarsousedComponent extends Component {
swiperRef = null
constructor(props) {
super(props)
this.state = {
message: 'Gallery',
text: '这就是测试数据',
defaultActiveKey: ['1'],
config: {
loop: true,
observer: true,
observeParents: true,
autoplay: {
delay: 3000,
stopOnLastSlide: false,
disableOnInteraction: false,
},
preloadImages: false,
lazy: true,
speed: 500,
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
pagination: {
el: '.swiper-pagination',
bulletElement: 'li',
hideOnClick: true,
clickable: true,
},
on: {
slideChange: function () {
console.log(this.activeIndex)
},
},
},
}
this.goNext = this.goNext.bind(this)
}
componentDidMount() {}
render() {
return (
<Fragment>
<AwesomeSwiper
ref={(ref) => (this.swiperRef = ref)}
config={this.state.config}
className="swiperAll"
>
<div className="swiper-wrapper">
<div className="swiper-slide">
<img src={imgurl1} alt="" />
</div>
<div className="swiper-slide">
<img src={imgurl2} alt="" />
</div>
<div className="swiper-slide">
<img src={imgurl3} alt="" />
</div>
<div className="swiper-slide">
<img src={imgurl1} alt="" />
</div>
<div className="swiper-slide">
<img src={imgurl2} alt="" />
</div>
<div className="swiper-slide">
<img src={imgurl3} alt="" />
</div>
</div>
<div className="swiper-button-prev"></div>
<div className="swiper-button-next"></div>
<div className="swiper-pagination"></div>
</AwesomeSwiper>
</Fragment>
)
}
goNext(e) {
console.log(e)
}
}
export default CarsousedComponent