【发布时间】:2018-12-24 03:03:41
【问题描述】:
我正在尝试通过axios 从jsonplaceholder 获取数据并迭代该数据并将该数据放入reactstrap 表中。我收到错误消息:Expected an assignment or function call and instead saw an expression。我不完全确定我在这里做错了什么。任何帮助是极大的赞赏。
这是我的代码:
render() {
const data = axios.get("https://jsonplaceholder.typicode.com/todos")
.then(response =>
this.data = response.data,
this.data.forEach((item) => {
<tr>
<td>{item.userId}</td>
<td>{item.id}</td>
<td>{item.title}</td>
<td>{item.completed}</td>
</tr>
})
)
return (
<div className="App">
<header className="App-header">
<Table>
<thead>
<tr>
<th>
User ID
</th>
<th>
ID
</th>
<th>
Title
</th>
<th>
Completed
</th>
</tr>
</thead>
<tbody>
{
data
}
</tbody>
</Table>
</header>
</div>
);
}
}
错误是我尝试在data 变量中创建表格行<tr> 标记。
【问题讨论】:
标签: reactjs axios reactstrap