8 글 보임 - 1 에서 8 까지 (총 8 중에서)
-
글쓴이글
-
2022년 8월 21일 15:56 #43369
정민참가자이미지에 링크를 넣어 해당 id값의 페이지로 넘어가는것은 구현했는데 사진이 다 똑같은 제품 사진으로 되어 있습니다. 같은 방식으로 <img src={"https://codingapple1.github.io/shop/shoes"+props.i+"jpg"} width="100%" alt="img"/> 이렇게 접근했더니 이미지가 깨져버리네요 이런건 어떤식으로 접근해야 하나요?
2022년 8월 24일 19:05 #43932
정민참가자App.js > card 컴포넌트에서 받아오는 props와 detail 컴포넌트에서 받아오는 props가 다른 것 같습니다. console data를import 했는데 props는 출력이 되는데 props.i가 출력이 안됩니다.
import { useEffect, useState } from "react"; import { useParams } from "react-router-dom"; import data from "../data";
function Detail(props) { useEffect(() => { setTimeout(() => { setAlert(false); }, 2000); }, []);
useEffect(() => { if (isNaN(num) === true) { alert("숫자만 입력하세요"); } });
let [count, setCount] = useState(0); let [alert, setAlert] = useState(true);
let { id } = useParams(); let [num, setNum] = useState("");
return ( <div> <div className="container"> {alert === true ? ( <div className="alert alert-warning">2초 안에 클릭하면 ...!!!!</div> ) : null}
{count} <button onClick={() => { setCount(count + 1); }} > 버튼 </button> <div className="row"> <div className="col-md-6"> <img src={ "https://codingapple1.github.io/shop/shoes" + props.i + ".jpg" } width="100%" alt="shoes" /> </div> <div className="col-md-6"> <h4 className="pt-5">{props.shoes[id].title}</h4> <p>{props.shoes[id].content}</p> <p>{props.shoes[id].price}원</p>
<button className="btn btn-danger">주문하기</button> </div> </div> </div> </div> ); }
export default Detail;
-
글쓴이글
8 글 보임 - 1 에서 8 까지 (총 8 중에서)
- 답변은 로그인 후 가능합니다.