如何计算React Redux中的所有addTocart产品总价
<div className='container py-4 my-5'>
{item.length === 0 ? (
<p>
cart is empty, <NavLink to='/'>continoue shopping</NavLink>
</p>
) : (
item.map((cart) => {
return (
<div className='row py-5 border-bottom'>
<>
<div className='col-md-4'>
<img
src={cart.image}
alt=''
style={{ width: '100%', height: '300px', objectFit: 'contain' }}
/>
</div>
<div className='col-md-4'>
<h3> {cart.title} </h3>
<p className='lead'> {cart.description} </p>
<p>Quantity: {cart.qty}</p>
<strong className='lead fw-bold'>
{' '}
price: {cart.price * cart.qty}{' '}
</strong>
<div className='mt-4'>
<button
className='btn btn-outline-dark me-4'
onClick={() => Decrement(cart)}
>
<i className='fa fa-minus'></i>
</button>
<button
className='btn btn-outline-dark'
onClick={() => addIncrement(cart)}
>
<i className='fa fa-plus'></i>
</button>
</div>
</div>
</>
</div>
);
})
)}
<div className='checkout'>
<h2 className='my-4'>total price: </h2>
<button className='btn btn-outline-dark px-5 py-2 green'>Checkout</button>
</div>
</div>;
我正在使用简单的反应显示在购物车组件中的产品,我只是让如何计算所有购物车产品的总价格感到困惑。它是一个基于REDUX的Application,我正在从“通过MAP功能中的CART组件中使用Eletrector”获取数据。是否有可能仅计算所有我只是添加的所有购物车的总价格。”
<div className='container py-4 my-5'>
{item.length === 0 ? (
<p>
cart is empty, <NavLink to='/'>continoue shopping</NavLink>
</p>
) : (
item.map((cart) => {
return (
<div className='row py-5 border-bottom'>
<>
<div className='col-md-4'>
<img
src={cart.image}
alt=''
style={{ width: '100%', height: '300px', objectFit: 'contain' }}
/>
</div>
<div className='col-md-4'>
<h3> {cart.title} </h3>
<p className='lead'> {cart.description} </p>
<p>Quantity: {cart.qty}</p>
<strong className='lead fw-bold'>
{' '}
price: {cart.price * cart.qty}{' '}
</strong>
<div className='mt-4'>
<button
className='btn btn-outline-dark me-4'
onClick={() => Decrement(cart)}
>
<i className='fa fa-minus'></i>
</button>
<button
className='btn btn-outline-dark'
onClick={() => addIncrement(cart)}
>
<i className='fa fa-plus'></i>
</button>
</div>
</div>
</>
</div>
);
})
)}
<div className='checkout'>
<h2 className='my-4'>total price: </h2>
<button className='btn btn-outline-dark px-5 py-2 green'>Checkout</button>
</div>
</div>;
I'm showing products in cart component using simple react, im just confused how to calculate total price of all cart product. its an react redux based application, I'm getting data from "useSelector in cart component through map function. is there any possibility to just calculate total price of all cart which i just add."
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
降低
函数来计算总价:You can use the
reduce
function to calculate the total price: