React JS Swiper循环无法正确遍历对象的问题
P粉835428659
2023-08-15 22:44:32
<p>我的Swiper在React中无法工作,我尝试过多次修复,但是没有成功解决。Swiper已经是最新版本。</p>
<pre class="brush:php;toolbar:false;">import React from "react";
import "./testimonial.css";
import { Data } from "./Data";
import {Swiper, SwiperSlide} from "swiper/react";
import "swiper/css";
import "swiper/css/pagination";
import {Pagination} from "swiper/modules"
const Testimonials = () => {
return (
<section className="testimonial container section">
<h2 className="section_title">我的客户说</h2>
<span className="section_subtitle">推荐信</span>
<Swiper className="testimonial_container"
loop={true}
grabCursor={true}
spaceBetween={24}
pagination={{
clickable: true,
}}
breakpoints={{
576: {
slidesPerView: 2,
},
768: {
slidesPerView: 2,
spaceBetween: 48,
},
}}
modules={[Pagination]}>
{Data.map(({id,image,title,description})=>{
return(
<SwiperSlide className="testimonial_card" key={id}>
<img src={image} alt="" className="testiomonial_img"/>
<h3 className="testimonial_name">{title}</h3>
<p className="testimonial_description">{description}</p>
</SwiperSlide>
)
})}
</Swiper>
</section>
);
};
export default Testimonials;</pre>
<p>我尝试了不同的语法形式,但都没有成功。我希望能够无限滚动浏览我的对象,但它总是卡在第二个幻灯片上。</p>
我发现你的代码存在一些潜在问题: