问题描述
我最近开始学习 React,但在我的代码中无法实现 React Awesome Slider。 https://github.com/rcaferati/react-awesome-slider
到目前为止,这是我的代码。我正在尝试使 div 类项目作为滑块工作,但即使我的数据中显示了 3 个 id,它似乎只显示轮播中的第一个 id。
import "./Work.scss";
import { useState } from "react";
import AwesomeSlider from 'react-awesome-slider';
import 'react-awesome-slider/dist/styles.css';
export default function Work(){
const data = [
{
id: "1",icon: "asset/mobile.png",title: "Web Design",desc:
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. ",img:
"https://99designs-blog.imgix.net/blog/wp-content/uploads/2018/10/attachment_100040756-e1538485934255.jpeg?auto=format&q=60&fit=max&w=930",},{
id: "2",icon: "asset/globe.png",title: "Mobile Application",desc:
"Lorem Ipsum is simply dummy text of the printing and typesetting industry.",img:
"https://i.pinimg.com/originals/e9/c9/2f/e9c92f7869d682a6fa5a97fb8a298f30.jpg",{
id: "3",icon: "asset/writing.png",title: "branding",img:
"https://i.pinimg.com/originals/a9/f6/94/a9f69465d972a004ad581f245d6ad581.jpg",];
return(
<div className="work" id="work">
<h1>My Services</h1>
<div className="slider">
{data.map((d)=> (
<div className="container">
<AwesomeSlider>
<div className= "item">
<div className="left">
<div className="leftContainer">
<div className="imgContainer">
<img src= {d.icon}/>
</div>
<h2>{d.title}</h2>
<p>{d.desc} </p>
</div>
</div>
<div className="right">
<img src="https://99designs-blog.imgix.net/blog/wp-content/uploads/2018/10/attachment_100040756-e1538485934255.jpeg?auto=format&q=60&fit=max&w=930"/>
</div>
</div>
</AwesomeSlider>
</div>
))}
</div>
</div>
);
}
解决方法
试试这个(代码沙盒 - https://codesandbox.io/s/musing-mclean-8ukzs?file=/src/App.js。
在您显示的代码中,QWidget
嵌套在循环中,因此创建了它的多个实例。根据文档,应该只有一个实例应该包装您的循环机制。
顺便说一下,在您的循环中,最后一个 polygonButton.setOpaque(false);
标签有一个硬编码的 AwesomeSlider
- 确保它引用了您的对象数组中的一个字段:)。
src