gpt4 book ai didi

javascript - 如何展示单个产品?

转载 作者:行者123 更新时间:2023-12-03 08:39:00 25 4
gpt4 key购买 nike

美好的一天,
我想问你可以在React中显示一个产品卡/页面。
我已经尝试过了,但是没有成功。先感谢您:

 const product = products.find(x=> x.id === props.match.params.id)

return(
<div>
<Nav/>
<h1>product page</h1>
<p>{Product.name}</p>
)
产品代码页:
import React from 'react'
import Product from '../components/product'
import Nav from "../components/nav"
import Store from './store'
import products from '../data/products'

function ProductPage(props){
console.log(props.match.params.id)
const product = products.find(x=> x.id === props.match.params.id)

return(
<div>
<Nav/>
<h1>product page</h1>
<p>{Product.name}</p>









</div>
)
}

export default ProductPage
产品卡代码:
import React from 'react'
import Products from '../data/products'
import {Link} from 'react-router-dom'
function Product(props){
function HandleSubmit(e){
e.preventDefault()
alert('added to cart !')

}
return(
<div >
<ul className="products">
{Products.map(product=> (<li key={product.id} className="product">
<img src={product.img}></img>
<a href={"/product:" + product.id}><h1>{product.name}</h1></a>
<p>price: €{product.price}</p>
<form onSubmit={HandleSubmit}>
<button>Add to cart</button>
</form>

</li>
)

)}
</ul>
</div>
)
}
导出默认产品
产品代码数据:
export default  [
{
id: '1',
name: 'product1',
price: 30,
img: 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxMTEhUTExIVFhUSFxIYFRcVFxUVEhcWFxUXFhUVFRUYHSggGBolGxUVITEhJSkrLi4uFx8zODMtNygtLisBCgoKDg0OGhAQFy0dHyUtLS0tLS0tKy0tLS0tLS0tLS0tLS0tLS0tLS0uLS0tLS0rNS0tKy0tLS0tLS0tLS0tLf/AABEIAOEA4QMBEQACEQEDEQH/xAAcAAEAAgIDAQAAAAAAAAAAAAAAAgMBBAUGBwj/xABDEAABAwEEBwUECAQFBQEAAAABAAIRAwQSITEFQVFhcYGRBgcTIqFykrHwIzIzQlKCwdEUYqLhU2NzsvE0Q5PC0hf/xAAaAQEAAwEBAQAAAAAAAAAAAAAAAQIDBAUG/8QANRE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CXAbyy+Oa6ckbrLx+xZPR56z+nzeD03zB2LhfUxKNYw+9tSC08dtuu8EROPWOOxQ0tMTCqy1PrNjPHoplWlucM1eP6KIJbmidBWm0fYUH1P5gIpji90N5Sr1rNuUMMmfHi9u0R/n5c3ddEd1NZ0G0V20x+GkL7/fdAaeTltXBPWXnZe9qR/wBuu/j+P6d60L2LsVmgsohzx9+p9I+dovYNPsgLauOteUPMzdtzZeFrcPKOH8/V2BXcogICAgICAgICAgICAgIOK0x2cstqH09Bjz+KLtQcHthw6qtqxbnDbFnyYvYtr+eTqekO6izO+xrVaW4xUZ0MO/qWc4K9HdTvXLHtRE/T9vo61bu6W1j7OtQqD+a/Td0hw9VnOC3SXVXvXFPtVmPlP4cHae7fSTMrOH+xUpEcgXA+iicV/JpHbuzz/u18Yl3vui7OV7MbRUtFJ1Nz/DawOiYF5zjgThJb0WmKkxuZcHeHaaZIrWk75vRajA4FpEgggjUQcCFu8x4naO7O2sc5tNjXMBcGHxGgloPlJDogxC5Jw26PosfeWGax4pmJ68GkewOkcnWQuH+pQiffVfRX8mv+v7PPO/0n8Nmh3fW84fw4Z7VSlA91x+Cehv5JnvLs0Rwtv9JcvozuoryDWr02DWKYdUMcTdAPVXjBPWXLfvbHHsVmfjw/LuWiOwFioQTT8Z4+9WN/oyLg6Sta4qw8/N3jnydfDHu4fXm7Q1oAgCAMgMlq4WUBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQf/2Q=='
},



]

最佳答案

我在以下位置看到了错误:ProductPage。如果要显示产品名称。应该是:

<p>{product.name}</p>
或者您想显示产品卡:
  <div>
<Nav/>
<h1>product page</h1>
<p>{product.name}</p>
<Product/>
</div>

关于javascript - 如何展示单个产品?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63871918/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com