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>
我發現你的程式碼有一些潛在問題: