gpt4 book ai didi

javascript - 无法读取 mdbreact 中未定义的属性 '0'

转载 作者:行者123 更新时间:2023-12-02 23:40:07 27 4
gpt4 key购买 nike

嘿,大家好,我正在使用 mdbreact 制作购物车,但出现了一些错误。我正在使用本节中的代码:https://mdbootstrap.com/docs/react/sections/e-commerce/这是我的代码:

import React from "react";
import { MDBRow, MDBCol, MDBCard, MDBCardImage, MDBCardBody, MDBCardTitle, MDBCardText, MDBCardFooter, MDBIcon, MDBTooltip } from "mdbreact";

const Item = () => {
return (
<section className="text-center my-5">
<h2 className="h1-responsive font-weight-bold text-center my-5">
Our bestsellers
</h2>
<p className="grey-text text-center w-responsive mx-auto mb-5">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Fugit,
error amet numquam iure provident voluptate esse quasi, veritatis
totam voluptas nostrum quisquam eum porro a pariatur veniam.
</p>
<MDBRow>
<MDBCol lg="3" md="6" className="mb-lg-0 mb-4">
<MDBCard cascade narrow ecommerce>
<MDBCardImage
cascade
src="https://mdbootstrap.com/img/Photos/Horizontal/E-commerce/Vertical/1.jpg"
top
alt="sample photo"
overlay="white-slight"
/>
<MDBCardBody cascade className="text-center">
<a href="#!" className="grey-text">
<h5>Denim</h5>
</a>
<MDBCardTitle>
<strong>
<a href="#!">Denim trousers</a>
</strong>
</MDBCardTitle>
<ul className="rating">
<li>
<MDBIcon icon="star" />
</li>
<li>
<MDBIcon icon="star" />
</li>
<li>
<MDBIcon icon="star" />
</li>
<li>
<MDBIcon icon="star" />
</li>
<li>
<MDBIcon far icon="star" />
</li>
</ul>
<MDBCardText>
Neque porro quisquam est, qui dolorem ipsum quia dolor sit.
</MDBCardText>
<MDBCardFooter className="px-1">
<span className="float-left font-weight-bold">
<strong>49$</strong>
</span>
<span className="float-right">
<MDBTooltip
placement="top"
tag="a"
component="i"
componentClass="fa fa-shopping-cart grey-text ml-3"
tooltipContent="Add to cart"
/>
<MDBTooltip
placement="top"
tag="a"
component="i"
componentClass="fa fa-share-alt grey-text ml-3"
tooltipContent="Share"
/>
<MDBTooltip
placement="top"
tag="a"
component="i"
className="active"
componentClass="fa fa-heart ml-3"
tooltipContent="Added to watchlist"
/>
</span>
</MDBCardFooter>
</MDBCardBody>
</MDBCard>
</MDBCol>


</MDBRow>
</section>
);
}

export default Item;

日志说类型错误:无法读取未定义的属性“0”。这是 mdbreact 的问题还是其他问题?如果是的话,有人可以建议我使用reactjs的其他替代UI库吗? React Bootstrap 对我来说不太好,因为我不擅长 CSS。谢谢

最佳答案

错误出现在您的 MDBTooltip 实现中。来自 the documentation ,看来组件需要两个子组件,第一个是工具提示所附加的内容,第二个是内容。 Click here for a working example which implements the following code

import React from "react";
import { MDBBtn, MDBRow, MDBCol, MDBCard, MDBCardImage, MDBCardBody, MDBCardTitle, MDBCardText, MDBCardFooter, MDBIcon, MDBTooltip } from "mdbreact";

const Item = () => {
return (
<section className="text-center my-5">
<h2 className="h1-responsive font-weight-bold text-center my-5">
Our bestsellers
</h2>
<p className="grey-text text-center w-responsive mx-auto mb-5">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Fugit,
error amet numquam iure provident voluptate esse quasi, veritatis
totam voluptas nostrum quisquam eum porro a pariatur veniam.
</p>
<MDBRow>
<MDBCol lg="3" md="6" className="mb-lg-0 mb-4">
<MDBCard cascade narrow ecommerce>
<MDBCardImage
cascade
src="https://mdbootstrap.com/img/Photos/Horizontal/E-commerce/Vertical/1.jpg"
top
alt="sample photo"
overlay="white-slight"
/>
<MDBCardBody cascade className="text-center">
<a href="#!" className="grey-text">
<h5>Denim</h5>
</a>
<MDBCardTitle>
<strong>
<a href="#!">Denim trousers</a>
</strong>
</MDBCardTitle>
<ul className="rating">
<li>
<MDBIcon icon="star" />
</li>
<li>
<MDBIcon icon="star" />
</li>
<li>
<MDBIcon icon="star" />
</li>
<li>
<MDBIcon icon="star" />
</li>
<li>
<MDBIcon far icon="star" />
</li>
</ul>
<MDBCardText>
Neque porro quisquam est, qui dolorem ipsum quia dolor sit.
</MDBCardText>
<MDBCardFooter className="px-1">
<span className="float-left font-weight-bold">
<strong>49$</strong>
</span>
<span className="float-right">
<MDBTooltip
placement="top"
tag="a"
component="i"
componentClass="fa fa-shopping-cart grey-text ml-3"
tooltipContent="Add to cart"
>
<MDBBtn>Tooltip button</MDBBtn>
<div>
Tooltip content
</div>
</MDBTooltip>
<MDBTooltip
placement="top"
tag="a"
component="i"
componentClass="fa fa-share-alt grey-text ml-3"
tooltipContent="Share"
>
<MDBBtn>Tooltip button</MDBBtn>
<div>
Tooltip content
</div>
</MDBTooltip>
<MDBTooltip
placement="top"
tag="a"
component="i"
className="active"
componentClass="fa fa-heart ml-3"
tooltipContent="Added to watchlist"
>
<MDBBtn>Tooltip button</MDBBtn>
<div>
Tooltip content
</div>
</MDBTooltip>
</span>
</MDBCardFooter>
</MDBCardBody>
</MDBCard>
</MDBCol>
</MDBRow>
</section>
);
}

export default Item;

关于javascript - 无法读取 mdbreact 中未定义的属性 '0',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56118560/

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