上代码
1、 页面引入swiper
import { Swiper, SwiperSlide } from 'swiper/react';
import SwiperCore, { Pagination } from "swiper";
import 'swiper/swiper.min.css';
import 'swiper/swiper.scss';
import 'swiper/components/pagination/pagination.scss'
SwiperCore.use([Pagination]);
2、代码使用(轮播滑块1个时,则不展示小圆点)
<Swiper
spaceBetween={50}
initialSlide={1} //默认展示第几个滑块
observer={true} //修改swiper自己或子元素时,自动初始化swiper(如果数据是请求下来的一定要重新初始化)
observeParents={true} //修改swiper的父元素时,自动初始化swiper(如果数据是请求下来的一定要重新初始化)
pagination={{
// el:'.swiper-pagination',
clickable:true,
}}
>
{
phoneList && phoneList.length >0 && phoneList.map((items,index) => {
return (
<SwiperSlide key={index}>
<div className='heatbox' key={index+1}>
轮播内容
</div>
</SwiperSlide>
)
})
}
</Swiper>
|