我试图使用React的map函数来显示地图元素。每个地图元素都有一个图像。如果我查看这个数组,就会看到这个数组中的内容,所以它被填充了。图片采用Base64格式。如果我试图用来自map函数之外的数组的图像来呈现一个普通的图像标记,它就是这样工作的!所以一定是因为地图函数--就在哪里?
{alleBilder.length &&
alleBilder.map((bild, index) => {
<Col md={3} xs={6}>
<Card className={classes.root}>
<CardActionArea>
<img src={bild.bild}></img>
<CardContent>
<Typography gutterBottom variant="h5" component="h2">
Lizard
</Typography>
<Typography
variant="body2"
color="textSecondary"
component="p"
>
Lizards are a widespread group of squamate reptiles, with
over 6,000 species, ranging across all continents except
Antarctica
</Typography>
</CardContent>
</CardActionArea>
<CardActions style={{ float: "right" }}>
<IconButton aria-label="add to favorites">
<FavoriteIcon />
</IconButton>
</CardActions>
</Card>
</Col>;
})}发布于 2021-03-05 14:24:25
你在搅乱map的回调。您应该从回调中返回jsx,但没有返回任何内容。请看如何在JSX中使用map:
const numbers = [1, 2, 3, 4, 5];
const listItems = numbers.map((number) =>
<li>{number}</li>
);相当于:
const numbers = [1, 2, 3, 4, 5];
const listItems = numbers.map((number) =>
(<li>{number}</li>)
);相当于:
const numbers = [1, 2, 3, 4, 5];
const listItems = numbers.map((number) => {
return (<li>{number}</li>)
}
);https://stackoverflow.com/questions/66494061
复制相似问题