django - 我不断收到此错误:TypeError: data.map is not a function
问题描述
我正在尝试使用 django 创建一个站点并做出反应,但是当我尝试查看它时,我不断收到此错误 TypeError: data.map is not a function
。以下是我的代码,我似乎不知道问题所在
我正在尝试使用 django 创建一个站点并做出反应,但是当我尝试查看它时,我不断收到此错误 TypeError: data.map is not a function。以下是我的代码,我似乎不知道问题所在
class ProductList extends React.Component {
state = {
loading: false,
error: null,
data: []
};
componentDidMount() {
this.setState({ loading: true });
axios
.get(productListURL)
.then(res => {
this.setState({ data: res.data, loading: false });
})
.catch(err => {
this.setState({ error: err, loading: false });
});
}
render() {
const { data, error, loading } = this.state;
return (
<Container>
{error && (
<Message
error
header="There was some errors with your submission"
content={JSON.stringify(error)}
/>
)}
{loading && (
<Segment>
<Dimmer active inverted>
<Loader inverted>Loading</Loader>
</Dimmer>
<Image src="/images/wireframe/short-paragraph.png" />
</Segment>
)}
<Item.Group divided>
{data.map(item => {
return <Item key={item.id}>
<Item.Image src={item.image} />
<Item.Content>
<Item.Header as='a'>{item.title}</Item.Header>
<Item.Meta>
<span className='cinema'>{item.category}</span>
</Item.Meta>
<Item.Description>{item.description}</Item.Description>
</Item.Content>
</Item>
})}
</Item.Group>
</Container>
);
}
}
export default ProductList```
解决方案
推荐阅读
- python - 我如何为python中的字节保留内存并在nasmx64程序集中一一读取?
- c# - Serilog - .Net Core 3.1 - 控制台应用程序 - 不记录到文件(但记录到控制台)
- eclipse - Eclipse:如何更改当前单词背景颜色?
- java - Retrofit/OkHttp 移除 Transfer-Encoding 标头
- android - 无法使用 Android Management API 重新启动设备
- node.js - 有没有使用 Puppeteer 消除所有模式和 cookie 警告的通用方法?
- azure-devops - 在 azure devops 中签署 android 应用程序包时出错
- python - Python Tkinter 按钮数量根据选定的 RadioButton 更改
- c# - 如何使用 LINQ 从数据库中返回两个特定列?
- wpf - 依赖属性未在初始绑定时传递默认值