gpt4 book ai didi

javascript - 如何使用 Material UI 默认组件

转载 作者:行者123 更新时间:2023-12-04 13:50:40 25 4
gpt4 key购买 nike

我一直在使用bootstrap,发现material ui也是一个很好的框架,并决定开始学习如何使用它。
在进入 MUI 组件时,我被卡住了。我想知道如何使用默认的 MUI 组件
无需自定义。例如,我想复制 card component并在浏览器上输出。
例如,其中一份文件的代码是:

import * as React from 'react';
import Card from '@mui/material/Card';
import CardContent from '@mui/material/CardContent';
import CardMedia from '@mui/material/CardMedia';
import Typography from '@mui/material/Typography';
import { Button, CardActionArea, CardActions } from '@mui/material';

export default function MultiActionAreaCard() {
return (
<Card sx={{ maxWidth: 345 }}>
<CardActionArea>
<CardMedia
component="img"
height="140"
image="/static/images/cards/contemplative-reptile.jpg"
alt="green iguana"
/>
<CardContent>
<Typography gutterBottom variant="h5" component="div">
Lizard
</Typography>
<Typography variant="body2" color="text.secondary">
Lizards are a widespread group of squamate reptiles, with over 6,000
species, ranging across all continents except Antarctica
</Typography>
</CardContent>
</CardActionArea>
<CardActions>
<Button size="small" color="primary">
Share
</Button>
</CardActions>
</Card>
);
}

在尝试在浏览器上输出相同的组件时,我这样做:
import * as React from 'react';
import Card from '@mui/material/Card';
import CardActions from '@mui/material/CardActions';
import CardContent from '@mui/material/CardContent';
import CardMedia from '@mui/material/CardMedia';
import Button from '@mui/material/Button';
import Typography from '@mui/material/Typography';

const DefaultCard = () => {
return (
<Card sx={{ maxWidth: 345 }}>
<CardMedia
component=""
alt="Yes"
height="140"
image=""
/>
<CardContent>
<Typography gutterBottom variant="h5" component="div">
Lizard
</Typography>
<Typography variant="body2" color="text.secondary">
Lizards are a widespread group of squamate reptiles, with over 6,000
species, ranging across all continents except Antarctica
</Typography>
</CardContent>
<CardActions>
<Button size="small">Share</Button>
<Button size="small">Learn More</Button>
</CardActions>
</Card>
);
}

export default DefaultCard
但是,我不断收到以下错误
Error in ./~/@mui/material/node/ButtonBase/TouchRipple.js
Module parse failed: C:\dev\frontend\node_modules\@mui\material\node\ButtonBase\TouchRipple.js Unexpected token (257:46)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (257:46)
@ ./~/@mui/material/node/ButtonBase/ButtonBase.js 34:42-66

Error in ./~/@mui/material/node/styles/createTransitions.js
Module parse failed: C:\dev\frontend\node_modules\@mui\material\node\styles\createTransitions.js Unexpected token (58:40)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (58:40)
@ ./~/@mui/material/node/styles/createTheme.js 29:48-78
我对错误一无所知。我希望有人帮我指出我做错了什么以及如何消除它

最佳答案

尝试删除 node_modulespackage-lock.jsonyarn/lock并再次安装

关于javascript - 如何使用 Material UI 默认组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69824415/

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