我学习 React 并遵循本教程,但即使我有相同的代码,结果也不一样。从教程中我想要一个像这样的网格:
但我得到的是:
import React, { Component } from 'react';
import { connect } from "react-redux";
import { withStyles } from '@material-ui/styles';
import { Grid, Paper, Typography } from "@material-ui/core";
import Card from "@material-ui/core/Card";
import CardActionArea from "@material-ui/core/CardActionArea";
import CardContent from "@material-ui/core/CardContent";
const images = require.context('../../public/images', true);
export class Posts extends Component {
constructor() {
super();
}
componentDidUpdate(prevProps) {
}
render() {
const { classes } = this.props;
return (
<div style={{ marginTop: 20, padding: 30 }}>
<Grid container spacing={40} justify="center">
{this.props.books.map(post => (
<Grid item key={post.title} Box width={1 / 4}>
<Card>
<CardActionArea>
<CardContent>
<Typography gutterBottom variant="h5" component="h2">
{post.title}
</Typography>
<Typography component="p">{post.description}</Typography>
<Typography component="p">{post.author}</Typography>
<Typography component="p">{post.genre}</Typography>
<Typography component="p">{post.publish_date}</Typography>
<Typography component="p">{post.price}</Typography>
</CardContent>
</CardActionArea>
</Card>
</Grid>
))}
</Grid>
</div>
);
}
}
function mapStateToProps(state) {
return {
books: state.reducer.booksList
}
}
export default connect(mapStateToProps)(withStyles(styles)(Posts));
我究竟做错了什么?我认为这是迫使卡片变大的文本,但我还没有阅读过如何限制文本(如果可能的话)